Home > Enterprise >  Get USB detail info from PDEV_BROADCAST_DEVICEINTERFACE in Windows
Get USB detail info from PDEV_BROADCAST_DEVICEINTERFACE in Windows

Time:09-18

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...)

CodePudding user response:

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

More information and a sample can be found here...

  • Related