I'm enumerating device manager tree using the CM_Locate_DevNode()
, CM_Get_Child()
and CM_Get_DevNode_Registry_Property()
APIs. I'm able to get the device instance handle.
Using that handle I'm trying to get the device handle to query the string descriptor of the device.
Are both device instance handle and device handle same or is there any way to get the device handle from device instance handle?
No, they are not the same. One is called Device Instance ID, and the other is called the Device Path.
Your question is similar to this one.
In order to get a USB String descriptor from a device, given its Device Instance ID, you need to:
GetInterfaces
function I'm providing belowThis function returns a list of NULL-terminated Device Paths (that's what we get from
CM_Get_Device_Interface_List
)You need to pass it the Device Instance ID, and the wanted interface
GUID
, which, for a USB HUB, isSince both the Device Instance ID and interface GUID are specified, it is highly likely that
CM_Get_Device_Interface_List
will return a single Device Path for that interface, but technically you should be prepared to get more than one result.I used a slight variation of this function successfully in production code for getting the Device Interface of a USB HUB (
GUID_CLASS_USBHUB
): I used the resulting Device Path with CreateFile and opened it succesfully.It is responsibility of the caller to
delete[]
the returned list if the function returns successfully (return code 0)