Получить интерфейсы девайса.
#39071639
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Есть такой код
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114.
const uint DIGCF_DEFAULT = 0x00000001; // only valid with DIGCF_DEVICEINTERFACE
const uint DIGCF_PRESENT = 0x00000002;
const uint DIGCF_ALLCLASSES = 0x00000004;
const uint DIGCF_PROFILE = 0x00000008;
const uint DIGCF_DEVICEINTERFACE = 0x00000010;
[StructLayout(LayoutKind.Sequential)]
struct SP_DEVICE_INTERFACE_DATA
{
public Int32 cbSize;
public Guid interfaceClassGuid;
public Int32 flags;
private UIntPtr reserved;
};
[StructLayout(LayoutKind.Sequential)]
struct SP_DEVINFO_DATA
{
public uint cbSize;
public Guid classGuid;
public uint devInst;
public IntPtr reserved;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
public int cbSize;
public char devicePath;
//alternative
//[MarshalAs(UnmanagedType.ByValTStr, SizeConst = BUFFER_SIZE)]
//public string DevicePath;
}
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern IntPtr SetupDiGetClassDevs(
ref Guid ClassGuid,
[MarshalAs(UnmanagedType.LPTStr)] string Enumerator,
IntPtr hwndParent,
uint Flags
);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern Boolean SetupDiEnumDeviceInterfaces(
IntPtr hDevInfo,
//ref SP_DEVINFO_DATA devInfo,
IntPtr devInfo,
ref Guid interfaceClassGuid,
UInt32 memberIndex,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern Boolean SetupDiGetDeviceInterfaceDetail(
IntPtr hDevInfo,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
UInt32 deviceInterfaceDetailDataSize,
out UInt32 requiredSize,
ref SP_DEVINFO_DATA deviceInfoData
);
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiDestroyDeviceInfoList
(
IntPtr DeviceInfoSet
);
[DllImport("setupapi.dll", SetLastError = true)]
static extern bool SetupDiEnumDeviceInfo(
IntPtr DeviceInfoSet,
uint MemberIndex,
ref SP_DEVINFO_DATA DeviceInfoData
);
public IntPtr GetBleHandle(string guid)
{
SP_DEVICE_INTERFACE_DATA did = new SP_DEVICE_INTERFACE_DATA();
SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA();
//SP_DEVINFO_DATA dev_info = new SP_DEVINFO_DATA();
IntPtr hComm = IntPtr.Zero;
Guid bluetooth_interface_guid = new Guid(guid);
IntPtr hdi = SetupDiGetClassDevs(ref bluetooth_interface_guid, null, IntPtr.Zero, DIGCF_ALLCLASSES | DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (hdi == INVALID_HANDLE_VALUE) return IntPtr.Zero;
bool success = true;
uint i = 0;
while (success)
{
// create a Device Interface Data structure
did.cbSize = Marshal.SizeOf(did);
//dd.cbSize = (uint)Marshal.SizeOf(dd);
//success = SetupDiEnumDeviceInfo(hdi, i, ref dd); //here success = true
// start the enumeration
success = SetupDiEnumDeviceInterfaces(hdi, IntPtr.Zero, ref bluetooth_interface_guid, 0, ref did);
if (success)
{
//some code
i++;
}
}
SetupDiDestroyDeviceInfoList(hdi);
return hComm;
}
пробовал несколько Guid, метод SetupDiEnumDeviceInterfaces всегда возвращает false . что я делаю не так?
|
|