I am using the SetupDiEnumDeviceInterfaces
function to get the device interfaces that are contained in a device information set. But the GUID is not passing "SP_DEVICE_INTERFACE_DATA
" structure. Here is my code snippet.
I have tried to see what is the issue by using GetLastError
.It always returns zero.
//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;
}
any help is appreciated. Thanks in adv.