[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Returns Wrong Parameter Error for PInvoke Call,..

Kerem G?mr?kc?

8/11/2008 3:01:00 AM

Hi,

i get a "Wrong Parameter" from Marshal.GetLastWin32Error() on using this:


[StructLayout(LayoutKind.Sequential)]
public class SP_DEVINFO_DATA
{
public int cbSize;
public Guid classGuid;
public int devInst;
public ulong reserved;
};

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
internal class SP_DRVINFO_DATA
{
public System.UInt32 cbSize;
public System.UInt32 DriverType;
public System.IntPtr Reserved;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public System.String Description;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public System.String MfgName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public System.String ProviderName;
public System.Runtime.InteropServices.ComTypes.FILETIME
DriverDate;
public System.UInt64 DriverVersion;
}

[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError =
true)]
private static extern bool SetupDiGetSelectedDriver
(
System.IntPtr DeviceInfoSet,
[In]ref SP_DEVINFO_DATA DeviceInfoData,
[Out]out SP_DRVINFO_DATA DriverInfoData
);

The "DeviceInfoSet" and "DeviceInfoData" of the Call are valid,
but something goes wrong while marshalling data between the
managed and unmanaged border. Something must be wrong
with my declarations,.....but what? I am certain, that it is some
stuff on the "SP_DRVINFO_DATA",...any ideas?

TIA,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.co...
Latest Open-Source Projects: http://entwicklung...
-----------------------
"This reply is provided as is, without warranty express or implied."

1 Answer

Pavel Minaev

8/11/2008 6:08:00 AM

0

On Aug 11, 7:01 am, Kerem Gümrükcü <kareem...@hotmail.com> wrote:
> Hi,
>
> i get a "Wrong Parameter" from Marshal.GetLastWin32Error() on using this:
>
>         [StructLayout(LayoutKind.Sequential)]
>         public class SP_DEVINFO_DATA
>         {
>             public int cbSize;
>             public Guid classGuid;
>             public int devInst;
>             public ulong reserved;

Why do you use "ulong" for "reserved" here? It's ULONG_PTR in the API
declaration, and, unless you're on x64, this is equivalent to
"unsigned long", which is uint in C#, not ulong. Though in this case,
to remain 64-bit clean, it's best to just use UIntPtr.

Anyway, assuming you used Marshal.SizeOf() to set cbSize, you've got a
wrong size in it with your declaration - perhaps it is the reason.