I would like to check if there is any WinAPI which is able to query/obtain the total number of disk drive devices.
Currently, I am doing this in the following way which is not ideal and not the best implementation:
int numDrives = 0;
sprintf( szDevname, "\\.\PHYSICALDRIVE%d", pdNumber );
// create a handle to the device
handle = CreateFileA( szDevname,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
if ( handle == INVALID_HANDLE_VALUE )
// Not a good way to check because there could be cases
// where a drive could be removed, for example a USB drive,
// which might result in the \.PHYSICALDRIVE%d numbering
// to have a gap
Any ideas of any WinAPI that can do this?