473,499 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returns Wrong Parameter Error for PInvoke Call,..

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.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

Aug 11 '08 #1
1 1697
On Aug 11, 7:01*am, Kerem Gümrükcü <kareem...@hotmail.comwrote:
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.
Aug 11 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4936
by: Bob Hairgrove | last post by:
We are having problems retrieving diagnostic information from a DB2 database (server is 7.1.x, client is 8.1). The SQLGetDiagRec() function, when called on a valid DB2 statement handle, always...
15
13024
by: XZ | last post by:
Hi everyone, this is really confusing to me: #include <stdio.h> main(int argc, char **argv) { printf("argv = %f\n",(double)atof(argv)); printf("argv = %d\n\n",atoi(argv)); } $ a.out a argv...
3
3447
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is...
7
9681
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
8
6641
by: Rajesh Soni | last post by:
Hi! I'm getting a PInvoke error while trying to execute the following code... declaration: Structure POINTAPI Dim x As IntPtr
4
5250
by: Steve Richter | last post by:
I have a C++ forms project that I am adding some unmanaged code to. I have a member function of the Form1 class that returns a String^ holding the text of the last win32 error. The code is...
2
2461
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the...
3
1791
by: =?Utf-8?B?TWFyZWs=?= | last post by:
Hi As well as trying to call a fortran dll with a structure parameter from a C# front end, we are trying to do this using AssemblyBuilder and MethodInfo to do it dynamically. Ultimately this will...
1
1530
by: keerthikarani | last post by:
hi, I m using the following code in vb.net, but it shows me some error, can u explain why this error occurs and how to rectify it, but the following code works fine in vb Private Declare...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.