Get USB detail info from PDEV_BROADCAST_DEVICEINTERFACE in Windows

Issue

case WM_DEVICECHANGE:
{
    PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lparam;
    PDEV_BROADCAST_DEVICEINTERFACE lpdbv = (PDEV_BROADCAST_DEVICEINTERFACE)lpdb;
    std::string path;
    if (lpdb->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
    {
      
        path = std::string(lpdbv->dbcc_name);
        switch (wparam)
        {
        case DBT_DEVICEARRIVAL:
            std::cout << "new device connected: " << path << "\n";
            break;

        case DBT_DEVICEREMOVECOMPLETE:
            std::cout << "device disconnected: " << path << "\n";
            break;
        }
    }
    break;
}

I write a small Windows console app to detect usb connect/disconnect event by listen WM_DEVICECHANGE message.

How can i get more info about which usb is connected/disconnected by PDEV_BROADCAST_DEVICEINTERFACE and PDEV_BROADCAST_DEVICEINTERFACE (name, descripton, storage size, manufacture…)

Solution

The SetupAPI, specifically SetupDiGetClassDevs+SetupDiEnumDeviceInfo+SetupDiGetDeviceInstanceId+SetupDiGetDeviceRegistryProperty should get you started.

More information and a sample can be found here

Answered By – Anders

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published