🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Bob Reeves Wed, 02 May 2007 15:23
Error handling Flash Card Reader?
#2095
Author: Bob Reeves
Date: Wed, 02 May 2007 15:23
32 lines
2025 bytes
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
Re: Error handling Flash Card Reader?
#2001
Author: Mark Jacobs
Date: Thu, 03 May 2007 18:19
18 lines
1563 bytes
"Bob Reeves" <bob@somethinxtra.com> wrote in message 
news:4638ae13$1@newsgroups.borland.com...
> 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 
Re: Error handling Flash Card Reader?
#2004
Author: Bob Reeves
Date: Fri, 04 May 2007 14:09
11 lines
1440 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads