SetupDiEnumDeviceInterfaces returns error 87

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,<br/><br/>Im getting error 87 (ERROR_INVALID_PARAMETER) when calling SetupDiEnumDeviceInterfaces.<br/>Im using C# with VS 2005 and running on Windows XP SP3.<br/>Im using the following code:<br/>
<pre lang="x-c# [StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_DATA
{
public UInt32 cbSize;
public Guid ClassGuid;
public UInt32 DevInst;
public UInt32 Reserved;
//public IntPtr Reserved;
}

// Device interface data
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVICE_INTERFACE_DATA
{
public UInt32 cbSize;
public Guid InterfaceClassGuid;
public UInt32 Flags;
public UInt32 Reserved;
//public IntPtr Reserved;
}
[/code]
<br/>
<pre lang="x-c# private void testDeviceEnum()
{
bool winApiRetVal = true;
int lastError = 0;
IntPtr hDevInfo = IntPtr.Zero;
SP_DEVINFO_DATA deviceInfoData;
SP_DEVICE_INTERFACE_DATA interfaceData;

//Retrieve a device information set for the devices in a specified class
hDevInfo = SetupDiGetClassDevs(ref MY_GUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

if (hDevInfo.ToInt32() != INVALID_HANDLE_VALUE)
{
uint i = 0;
while (winApiRetVal)
{
// create a Device Interface Data structure
interfaceData = new SP_DEVICE_INTERFACE_DATA();
interfaceData.cbSize = (UInt32)Marshal.SizeOf(interfaceData);
interfaceData.InterfaceClassGuid = System.Guid.Empty;


// build a DevInfo Data structure
deviceInfoData = new SP_DEVINFO_DATA();
deviceInfoData.cbSize = (UInt32)Marshal.SizeOf(deviceInfoData);
deviceInfoData.ClassGuid = System.Guid.Empty;
deviceInfoData.DevInst = 0;
deviceInfoData.Reserved = IntPtr.Zero;

// enumerate the device interfaces
winApiRetVal = SetupDiEnumDeviceInterfaces(hDevInfo,
ref deviceInfoData,
ref MY_GUID,
i,
ref interfaceData);

if (!winApiRetVal)
{
lastError = Marshal.GetLastWin32Error();//Getting error 87 here
Console.WriteLine("SetupDiEnumDeviceInterfaces - error = " + lastError.ToString());
}

}
}
}<br/>[/code]
Any idea?
Thanks,
AssafT

View the full article
 
Back
Top