我想用SetupDiGetDeviceRegistryProperty 获取 usb 设备的 “总线关系” 这个特性,试了下 面这几个参数,都不行,
SPDRP_ENUMERATOR_NAME
SPDRP_SECURITY
SPDRP_SECURITY_SDS
后来找到了下 面的代码,用CM_Get_Parent 来获取总线关系。
Please find the complete code to get the DeviceID of a device parent:
// Enumerate imaging devices and get their parent's DeviceID
bool enumDevices ()
{
// Create a HDEVINFO with all "imaging devices"
HDEVINFO hDevInfo = SetupDiGetClassDevs
(&GUID_VideoInputDeviceCategory,
0L, // Enumerator
0L, // hwndParent
DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE)
return false;
// Enumerate through all USB devices in Set.
SP_DEVINFO_DATA deviceInfoData;
deviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
for (DWORD i=0; SetupDiEnumDeviceInfo (hDevInfo, i,
&deviceInfoData); i++)
{
ULONG hdevParent;
// Get parent device handle
if (CM_Get_Parent (&hdevParent, deviceInfoData.DevInst, 0) !=
CR_SUCCESS)
continue;
// Get device ID string length
ULONG ulSize = 0;
if (CM_Get_Device_ID_Size (&ulSize, hdevParent, 0) != CR_SUCCESS)
continue;
// Get parent device DeviceID
BYTE* strParentDeviceID = new BYTE [ulSize + 1];
if (CM_Get_Device_ID (hdevParent, strParentDeviceID, ulSize + 1,
0) != CR_SUCCESS)
continue;
delete [] strParentDeviceID;
}
// Cleanup
SetupDiDestroyDeviceInfoList (hDevInfo);
return true;
}