1

I've managed to check if a USB device is inserted through WM_DEVICECHANGE.

case WM_DEVICECHANGE:
{
    PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;

    switch(wParam)
    {
        case DBT_DEVICEARRIVAL:
        {
            if (lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
            {
                  // Get Information about the usb device inserted
            }
            return TRUE;
        }
    }
}

Now, I want to make sure that a right usb device was inserted by matching some kind of IDs and also I'll need to check the space available on the USB device.

One solution I can tell is to iterate through all the hardware devices until one matches with the information.

is there any another way to recognize the device upon insertion?

user675341
  • 13
  • 3

1 Answers1

4

VID and PID are sent with the DBT_DEVTYP_DEVICEINTERFACE message. You can then look in the device drivers for more information via SetupDiGetClassDevs/SetupDiEnumDeviceInfo/SetupDiGetDeviceInstanceId/SetupDiGetDeviceRegistryProperty.

Media is not necessary available at the time of the connection. Think about a card reader, it would register drive letters but the drives won't be ready until you get a card inserted and Windows generate a GUID_IO_MEDIA_ARRIVAL device event. You can then call GetDiskFreeSpaceEx on the drive letter to get the free space.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • 1
    I've got `USB\VID_0763&PID_1324\001DD0EC33B0SS6167D92815` I'm not sure what is the `001DD0EC33B0SS6167D92815` mean. thanks. – user675341 Aug 26 '11 at 15:33