Главная страница | назад





Article #19314: Replicating FindFirstFile's Windows NT behaviour in Windows 95

 Question and Answer Database

FAQ4314C.txt   :Replicating FindFirstFile's Windows NT behaviour in Windows 95
Category   :Windows API
Platform    :Windows 95
Product    :BC++4.5x,   BC++5.x,   C++Builder1.0,   C++Builder3.x,   C++Builder4.x,   

Question:
I've noticed that the WinAPI function FindFirstFile() 
has different behaviour in Win95 from WinNT.  If the 
drive in the path passed to FindFirstFile() isn't ready,
WinNT pops up a message box that says, for example:

   A:\ is not accessible. The device is not ready.

complete with stop icon and "Retry" and "Cancel" 
buttons.  The function doesn't return until the drive is
ready, or the user clicks "Cancel".  In Win95, the
function justs returns.  Why is this?  How can I get my 
app to have the same behaviour in Win95?

Answer:
The answer to "Why?", is that Win32 functions frequently
have subtle (and sometimes not so subtle) differences in
their behaviour between the two OS's.  You can replicate
the WinNT behaviour for FindFirstFile() in Win95 with 
the following code.  This code launches a message box
which is identical (except for the title "MyProgram", 
which you can change) to the message box launched by
Windows Explorer:

// Get the version of the OS
OSVERSIONINFO osInfo;
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

GetVersionEx(&osInfo);

HANDLE fh = FindFirstFile("a:\*.*", &fd);

// If we're running under Win95 ...
if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
   // Check the a: drive continuously until it's ready,
   // or the user decides to cancel
   while (fh = INVALID_HANDLE_VALUE)
   {
      if (MessageBox(NULL, 
          "A:\\ is not accessible.\n\n"
          "The device is not ready.", "MyProgram",
          MB_ICONSTOP | MB_RETRYCANCEL) == IDCANCEL)
      {
         break;
      }

      fh = FindFirstFile("a:\*.*", &fd);
   }
}


1/21/1999 2:57:30 PM
 

Last Modified: 01-SEP-99