Last Modification: February 25, 2000

How can I detect if there's a floppy in the disk drive?

You can call the GetVolumeInformation() API to find out whether there's a disk in a particular drive or not. Keep in mind to set the error mode to SEM_FAILCRITICALERRORS before doing it, otherwise, the standard "Drive Not Ready" dialog will pop up. Here's a short example:


BOOL IsDiskInDrive ( LPTSTR lpszDrive )
{
   UINT     errmode;
   TCHAR    szVolName[256];
   DWORD    dwMaxComSize;
   DWORD    dwFlags;
   TCHAR    szFS[256];
   BOOL     bRes;

   errmode = SetErrorMode ( SEM_FAILCRITICALERRORS );

   bRes = GetVolumeInformation ( lpszDrive,
                                 szVolName,
                                 sizeof(szVolName),
                                 NULL, &dwMaxComSize,
                                 &dwFlags,
                                 szFS, sizeof(szFS) );
   SetErrorMode ( errmode );
   return bRes;
}

This technique should also work for CD-ROM drives and other removable media.