Re: Help With PInvoke and SetupDiEnumDriverInfo/SP_DRVINFO_DATA
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 8 Mar 2007 17:18:39 +0100
"Rymfax" <cwalker@xxxxxxxxxxxxxx> wrote in message news:1173359040.875451.299600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I would really appreciate it if someone could help me figure out what
I'm doing wrong trying to PInvoke SetupDiEnumDriverInfo. All the
other PInvokes i've done up to this point work fine. Whenver I
PInvoke SetupDiEnumDriverInfo though, I get winerror.h code of 1784L,
which basically says it doesn't like my buffer, which I assume is the
structure.
Below is my PInvoke, my structure and a sample of my code. Please,
please PLEASE help me!
[DllImport("setupapi.dll", SetLastError = true)]
private static extern bool SetupDiEnumDriverInfo(IntPtr
DeviceInfoSet,
ref SP_DEVINFO_DATA DeviceInfoData, int DriverType, int
MemberIndex,
ref SP_DRVINFO_DATA DriverInfoData);
[StructLayout(LayoutKind.Sequential)]
public struct SP_DRVINFO_DATA
{
public int cbSize;
public int DriverType;
public IntPtr Reserved;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string Description;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string MfgName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string ProviderName;
public System.Runtime.InteropServices.ComTypes.FILETIME
DriverDate;
public long DriverVersion;
}
void EnumerateDriverList(IntPtr devInfoSet, SP_DEVINFO_DATA
devInfoData)
{
int memIndex = 0;
int drvErr = 0;
SP_DRVINFO_DATA drvData = new SP_DRVINFO_DATA();
drvData.cbSize = Marshal.SizeOf(typeof(SP_DRVINFO_DATA));
bool enumResult = SetupDiEnumDriverInfo(devInfoSet, ref
devInfoData, SPDIT_COMPATDRIVER,
memIndex, ref drvData);
if(!enumResult) drvErr = Marshal.GetLastWin32Error();
while (enumResult && drvErr != ERROR_NO_MORE_ITEMS)
{
// Never Gets to this point.
}
}
Try using the Unicode function by specifying [DllImport( setupapi), CharSet = CharSet.Unicode,..]
and do the same to your structure declarations...
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
Willy.
.
- Follow-Ups:
- References:
- Prev by Date: Re: F5 is running an older version of my project
- Next by Date: Re: CSharp with COM components in 64bit
- Previous by thread: Help With PInvoke and SetupDiEnumDriverInfo/SP_DRVINFO_DATA
- Next by thread: Re: Help With PInvoke and SetupDiEnumDriverInfo/SP_DRVINFO_DATA
- Index(es):