usb 设备的总线关系

我想用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;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值