BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error handling Flash Card Reader?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Bob Reeves
Guest





PostPosted: Wed May 02, 2007 8:23 pm    Post subject: Error handling Flash Card Reader? Reply with quote



Hoping this is a good place to post this..

I am accessing image files from a USB Compact Flash card reader and need to
catch the error if a flash card isn't in the reader.

Here is what I am trying to do, please assume all variables have been
declared and initialized..

old_err_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
SetLastError(-1);
dn = findfirst(FileName,&ffblk,0); // find first file
er = GetLastError();
if(er != -1) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, er, 0, buffer,
sizeof(buffer), 0);
ShowMsg("Unable to read Memory Card");
ShowMsg(buffer);
}
SetErrorMode(old_err_mode);


This works fine, catches the error and reports as expected, however if I
then insert a memory card into the reader and call the above code again it
gives me an invalid handle error. If I shut down and re-start the app it
will read the card without the error.

Looking like I missed re-setting something that will allow it to try to read
the drive the second time. Any ideas on what I need to do eliminate the
invalid handle error?

Thanks,
Bob
Back to top
Mark Jacobs
Guest





PostPosted: Thu May 03, 2007 11:19 pm    Post subject: Re: Error handling Flash Card Reader? Reply with quote



"Bob Reeves" <bob (AT) somethinxtra (DOT) com> wrote in message
news:4638ae13$1 (AT) newsgroups (DOT) borland.com...
Quote:
Here is what I am trying to do, please assume all variables have been
declared and initialized..
old_err_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
SetLastError(-1);
dn = findfirst(FileName,&ffblk,0); // find first file
er = GetLastError();
if(er != -1) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, er, 0, buffer,
sizeof(buffer), 0);
SNIP

Try changing if(er != -1) to if(er != -1 && dn !=0)
dn is non-zero if it didn't find anything.
--
Mark Jacobs
www.jacobsm.com
Back to top
Bob Reeves
Guest





PostPosted: Fri May 04, 2007 7:09 pm    Post subject: Re: Error handling Flash Card Reader? Reply with quote



That worked like a charm.. I did discover that if I read it a 3rd time it
would work. This with the combination of your sugestion tells me the error
code wasn't being reset the second time through even though the code
assigns -1 to SetLast Error().

Must be something I don't understand about SetLast Error() but now it
doesn't matter.. It works, thanks you saved me allot of trouble. I was going
to loop through it twice to get around the problem but your solution is much
better.

Bob
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.