J
Jason
Hello,
I'm trying to call this method from C# but it's returning false.
Marshal.GetLastWin32Error() returns 8 which means "Not enough storage is
available to process this command". Can someone elaborate what this means
please? Is this a marsahling parameter problem?
I've declared the method as
[DllImport("setupapi.dll")]
public static extern bool SetupDiEnumDeviceInterfaces(
IntPtr DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, ref Guid
InterfaceClassGuid,
int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData );
I set up the return data structure by
SP_DEVICE_INTERFACE_DATA devdata = new SP_DEVICE_INTERFACE_DATA();
devdata.SetSize();
I've hardcoded the size since I can't used sizeof().
Then I call
if( !SetupDiEnumDeviceInterfaces( info, null, ref guid, instance,
devdata ) )
....
Both SP_DEVINFO_DATA and SP_DEVICE_INTERFACE_DATA have been declared as
classes so I can pass null if needed.
[StructLayout(LayoutKind.Sequential)]
public class SP_DEVICE_INTERFACE_DATA
{
internal UInt32 cbSize;
internal Guid InterfaceClassGuid;
internal UInt32 Flags;
internal IntPtr Reserved;
public void SetSize()
{
cbSize = 32;
InterfaceClassGuid = Guid.NewGuid();
}
}
I've tried the same thing with C++ and it works. I don't really want to
create a managed C++ dll to use this function so I'd greatly appreciate any
suggestions to where I'm going wrong.
Regards,
Jason Browne.
I'm trying to call this method from C# but it's returning false.
Marshal.GetLastWin32Error() returns 8 which means "Not enough storage is
available to process this command". Can someone elaborate what this means
please? Is this a marsahling parameter problem?
I've declared the method as
[DllImport("setupapi.dll")]
public static extern bool SetupDiEnumDeviceInterfaces(
IntPtr DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, ref Guid
InterfaceClassGuid,
int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData );
I set up the return data structure by
SP_DEVICE_INTERFACE_DATA devdata = new SP_DEVICE_INTERFACE_DATA();
devdata.SetSize();
I've hardcoded the size since I can't used sizeof().
Then I call
if( !SetupDiEnumDeviceInterfaces( info, null, ref guid, instance,
devdata ) )
....
Both SP_DEVINFO_DATA and SP_DEVICE_INTERFACE_DATA have been declared as
classes so I can pass null if needed.
[StructLayout(LayoutKind.Sequential)]
public class SP_DEVICE_INTERFACE_DATA
{
internal UInt32 cbSize;
internal Guid InterfaceClassGuid;
internal UInt32 Flags;
internal IntPtr Reserved;
public void SetSize()
{
cbSize = 32;
InterfaceClassGuid = Guid.NewGuid();
}
}
I've tried the same thing with C++ and it works. I don't really want to
create a managed C++ dll to use this function so I'd greatly appreciate any
suggestions to where I'm going wrong.
Regards,
Jason Browne.