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.

I made a before and after enumeration using GetDriveType().

Thanks anyways tho.

Regards,

Gen

If your program is a regular GUI application, then you might consider using the code from Detecting Media Insertion or Removal. I.e. not involving RegisterDeviceNotification() at all.

I am already using those messages.

It does not properly give the index for any USB removable devices.

This question has already been answered. Start a new discussion instead.