java父系调用子系,获取usb设备父系或子代

///

/// 获取设备父系

///

///

///

private static bool TryGetDriverIdParent(string driver, out string resultDeviceID)

{

resultDeviceID = "";

try

{

int CM_LOCATE_DEVNODE_NORMAL = 0x00000000;

int CR_SUCCESS = 0x00000000;

UInt32 parentInst;

;

;

int apiResult = Win32.CM_Locate_DevNodeA(ref curInst, driver, CM_LOCATE_DEVNODE_NORMAL);

if (apiResult != CR_SUCCESS)

{

return false;

}

apiResult = Win32.CM_Get_Parent(out parentInst, (UInt32)curInst, CM_LOCATE_DEVNODE_NORMAL);

if (apiResult != CR_SUCCESS)

{

return false;

}

apiResult = Win32.CM_Get_Device_ID_Size(out pLen, parentInst, CM_LOCATE_DEVNODE_NORMAL);

if (apiResult != CR_SUCCESS)

{

return false;

}

];

//获取设备id字符串地址

apiResult = Win32.CM_Get_Device_ID(parentInst, ptrInstanceBuf, pLen, );

if (apiResult != CR_SUCCESS)

{

return false;

}

resultDeviceID = new string(ptrInstanceBuf);

return true;

}

catch (Exception ecException)

{

LogHelper.WriteErrorLog("获取父代" + ecException.Message, ecException);

return false;

}

}

[DllImport("setupapi.dll", SetLastError = true)]

public static extern int CM_Locate_DevNodeA(ref int pdnDevInst, string pDeviceID, int ulFlags);

[DllImport("setupapi.dll")]

public static extern int CM_Get_Parent(out UInt32 pdnDevInst, UInt32 dnDevInst, int ulFlags);

[DllImport("setupapi.dll", SetLastError = true)]

);

[DllImport("setupapi.dll", CharSet = CharSet.Unicode)]

public static extern int CM_Get_Device_ID(UInt32 dnDevInst, char[] buffer, int bufferLen, int flags);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值