Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top