Reputation: 711
I have been able to enumerate USB devices using the SetupAPI, and I've looked at the usbview application from the WDK, but I still can't figure out how to get the USB_DEVICE_DESCRIPTOR.
Can anyone point me in the right direction? Is it just not possible to get this information from the WinAPI in a nice way without starting at the Hub?
Upvotes: 5
Views: 7143
Reputation: 557
Your best bet would be to extract the info from the device path and use the SetupDi functions to get the other bits and pieces. As far as I know, the device path always follows the same convention. i.e.:
"\\?\usb#vid_0000&pid_1111#SERIAL#{GUID}" where 0000 is the VID and 1111 is the PID as hex strings. SERIAL is either the serial provided by the hardware or the OS-assigned serial value.
I personally found an instance where I absolutely wanted to get the device descriptor in order to pull the serial that way. In some instances, the OS was not recognizing the serial number provided by my hardware. I fixed that on the hardware side, but I still wanted to accommodate old hardware on the PC side. Below is my approach. There may be something better, but this is the best that I have come up with so far. You may still consider it to be "hack-ish" though.
-EDIT-
As Ben pointed out in the comments, you can skip steps 5, 6, and 7 by using CM_Get_Device_ID on the parent's dev node obtained in step 4. Change the slashes (\) in this string to pounds (#). Prepend "\\?\" and then append "#{f18a0e88-c30c-11d0-8815-00a0c906bed8}". Use that as your device path in step 8. This avoids iterating through all of the hub devices on your system :)
Upvotes: 1