How to find which device is connected to a USB port (HID or Disk drive) in C ++

I was able to list all the connected USB ports using SetupDi calls. Sample code is available in this one.

Please, can someone tell me how can I find which device is connected to the USB port, for example, be it any HID device or any drive?

Thanks.

+4
source share
1 answer

I would recommend looking at a sample USBView in the WDK. If you are not familiar with this, just run it - this tool scans the entire USB tree in the system and prints information and descriptor lists for each device.

In your case, I would start with the RefreshTree () function in this example, then you can follow this code to find out how it lists controllers, hubs, and finally devices. For each device found, you can look at bInterfaceClass in the interface descriptors to find out what types of interfaces it advertises (in your case, 0x03 for the HID Interface Class and 0x08 for the Mass Storage class).

The easiest way to get the source code for this example is to install the 7.1.0 WDK, which is currently available here: http://www.microsoft.com/en-us/download/details.aspx?id=11800

+1
source

Source: https://habr.com/ru/post/1493181/


All Articles