Re: Testing for file on possibly non-existing drive
From: Severian (severian_at_chlamydia-is-not-a-flower.com)
Date: 02/18/05
- Next message: YAN (Yet Another Newbie): "Question about Listview.. still :("
- Previous message: Rhett Gong [MSFT]: "RE: TreeView and TVITEMEX.iIntegral"
- In reply to: Peter Andersen: "Testing for file on possibly non-existing drive"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 18 Feb 2005 02:35:32 GMT
On Thu, 17 Feb 2005 13:45:05 -0800, "Peter Andersen"
<datpete@discussions.microsoft.com> wrote:
>Hello,
>
>I want to test the availablility of a database, which may be located on the
>harddrive or on a DVD (current location is in Registry).
>I try the following:
>
>if ((fd = OpenFile(filename, &ofs, OF_EXIST)) == HFILE_ERROR) {
> return FALSE;
>};
>
>However, IF the file being tested is on the external drive (e.g.
>D:\....\file) AND no disk is in the D: drive, then a dialog appears, which
>says
>
>
>There is no disk in the drive...
>Cancel Retry Continue
>
>
>HOWEVER hitting the Cancel button has NO effect - the control is not given
>back to the program.
>Actually the only way to get rid of the dialog is by inserting a CD/DVD (any
>disk that is) into the D: drive.
>
>How come?
>
>I have also tried to add OF_PROMPT but this gives the same effect.
>
>I would like to know of another way of testing for the existence of a file
>on a possibly non-present drive, which does NOT block the program, but simply
>returns false if there is no such drive.
>I am sure I am overlooking something obvious...
I *think* this is what you need:
SetErrorMode(SEM_FAILCRITICALERRORS);
This will cause such errors to return an error code rather than let
Windows try to fix things up before returning.
You may want:
SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
but I haven't found that necessary.
I have no idea why Cancel isn't working in your case, though.
-- Sev
- Next message: YAN (Yet Another Newbie): "Question about Listview.. still :("
- Previous message: Rhett Gong [MSFT]: "RE: TreeView and TVITEMEX.iIntegral"
- In reply to: Peter Andersen: "Testing for file on possibly non-existing drive"
- Messages sorted by: [ date ] [ thread ]