 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bob Reeves Guest
|
Posted: Wed May 02, 2007 8:23 pm Post subject: Error handling Flash Card Reader? |
|
|
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
|
Posted: Thu May 03, 2007 11:19 pm Post subject: Re: Error handling Flash Card Reader? |
|
|
"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
|
Posted: Fri May 04, 2007 7:09 pm Post subject: Re: Error handling Flash Card Reader? |
|
|
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 |
|
 |
|
|
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
|
|