我正在使用该SetupDiEnumDeviceInterfaces
函数来获取设备信息集中包含的设备接口。但是 GUID 没有通过“ SP_DEVICE_INTERFACE_DATA
”结构。这是我的代码片段。
我试图通过使用来查看问题所在。GetLastError
它总是返回零。
//GUID.
GetHidGuid(Myguid)
[DllImport("hid.dll", SetLastError = true)]
static extern unsafe void GetHidGuid(
ref GUID lpHidGuid);
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GUID
{
public int Data1;
public System.UInt16 Data2;
public System.UInt16 Data3;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] data4;
}
// SetupDiEnumDeviceInterfaces function.
public unsafe int CT_SetupDiEnumDeviceInterfaces(int memberIndex)
{
int ErrorStatus;
mySP_DEVICE_INTERFACE_DATA = new SP_DEVICE_INTERFACE_DATA();--> here is where i Have problem.GUID is zero.
mySP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(mySP_DEVICE_INTERFACE_DATA);
int result = SetupDiEnumDeviceInterfaces(
hDevInfo,
0,
ref MYguid,
memberIndex,
ref mySP_DEVICE_INTERFACE_DATA);
return result;
ErrorStatus = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
public unsafe struct SP_DEVICE_INTERFACE_DATA
{
public int cbSize;
public GUID InterfaceClassGuid;
public int Flags;
public int Reserved;
}
任何帮助表示赞赏。谢谢你的建议。