I use GetLogicalDrives()
to get all drives on my computer but that function shows not only present ready to use volumes but also empty flash-readers with no card in them. Next the GetDriveType()
shows code 2 for such volume. And that is no matter if the flash card is present or not in the slot. Some multi-readers produce many such non-existing drives, the question is how can I determine the correct status of such volume.
Trying to call FindFirstFile()
on such non-present drive produces visual error even in console app : Exception Processing Message c0000013 Parameters 75b3bf7c 4 75b3bf7c 75b3bf7c
After such error the code continues to run, but this annoying error shows up to the user in a window as the app would made a major crash.
So one method of dealing with that would be using FindFirstFile but I do not know any way to get that error out of the way of the user.
Finally I found it! The key to success here is GetVolumeInformation()
.
It returns 0 and sets last error to 21 when there is an empty card reader in usb slot. :)
Here are a few excellent choices:
In particular:
if( 2 == ::getDriveType( <driveletter> ))
Return values of function:
DRIVE_UNKNOWN 0: The drive type cannot be determined.
DRIVE_NO_ROOT_DIR 1: The root path is invalid; for example, there is no volume mounted at the specified path.
DRIVE_REMOVABLE 2: The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader.
DRIVE_FIXED 3: The drive has fixed media; for example, a hard disk drive or flash drive.
DRIVE_REMOTE 4: The drive is a remote (network) drive.
DRIVE_CDROM 5: The drive is a CD-ROM drive.
DRIVE_RAMDISK 6: The drive is a RAM disk.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With