Goal: Get USB drive letter upon insertion.
Done so far:
Detection of drive.
-------------------------------------------------------------
Im using the method of RegisterDeviceNotification()
WM_DEVICECHANGE // Received message
|
DBT_DEVICEARRIVAL // Received Message
|
DEV_BROADCAST_HDR // Pointer from lParam
|
PDEV_BROADCAST_VOLUME //Pointer from DEV_BROADCAST_HDR Pointer
When getting the index drive letter from dbcv_unitmask.
It works for DVD ( obviously ) but returns a -1 for USBs.
So I was going to try going though all possible drives, then check for the latest plugged in.
WIN32_FILE_ATTRIBUTE_DATA ad;
SYSTEMTIME Time;
GetFileAttributesEx( "L:\\", GetFileExInfoStandard, &ad );
FileTimeToSystemTime( &ad.ftCreationTime, &Time );
But it only has time for creation time, access time, write time.
Not being inserted.
Is there a better method to get a USB's drive letter the moment it is plugged in, I don't need a example code. Just some API names if possible.