473,624 Members | 2,281 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.GetLast Win32Error() on using this:
[StructLayout(La youtKind.Sequen tial)]
public class SP_DEVINFO_DATA
{
public int cbSize;
public Guid classGuid;
public int devInst;
public ulong reserved;
};

[StructLayout(La youtKind.Sequen tial,CharSet=Ch arSet.Unicode)]
internal class SP_DRVINFO_DATA
{
public System.UInt32 cbSize;
public System.UInt32 DriverType;
public System.IntPtr Reserved;

[MarshalAs(Unman agedType.ByValT Str, SizeConst = 256)]
public System.String Description;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 256)]
public System.String MfgName;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 256)]
public System.String ProviderName;
public System.Runtime. InteropServices .ComTypes.FILET IME
DriverDate;
public System.UInt64 DriverVersion;
}

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

The "DeviceInfo Set" 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_DAT A",...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 1704
On Aug 11, 7:01*am, Kerem Gümrükcü <kareem...@hotm ail.comwrote:
Hi,

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

* * * * [StructLayout(La youtKind.Sequen tial)]
* * * * 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
4947
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 returns SQL_SUCCESS_WITH_INFO instead of SQL_SUCCESS, as the documentation says it should. SQL_SUCCESS_WITH_INFO, according to the documentation excerpt from "The ODBC Programmer's Reference" posted below, means that the text buffer for retrieving...
15
13065
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 = 97.000000
3
3459
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 that my form appears to be blocked while the background thread is running. I am very familir with threads in unmanaged code but am just getting into them in C#. Are there issues I need to be aware of with regards to threading a simple pinvoke...
7
9701
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 for this being to stop the user thinking the application has frozen when in fact it is just waiting for a long SP to complete. Another reason for doing it like this is that I also have had a problem in the past where the SP takes longer than the...
8
6649
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
5254
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 failing on the call to FormatMessage. Cannot marshal 'parameter #7': Pointers cannot reference marshaled structures. Use ByRef instead. how do I pass the argument ByRef and why is managed code involved in this api call? FormatMessage is an...
2
2478
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 value of one of the parameters that were passed to the method. Is this possible? Even if I have to use PInvoke to do so? I can currently find the parameter TYPEs using reflection but I can not figure out to obtain the values. Thanks,
3
1798
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 be done using a configuration file, but in the first instance I am trying to do this using code. The FORTRAN structure looks like this: TYPE Type1 ! Scalars plus fixed dimension arrays SEQUENCE
1
1548
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 Function SQLDataSources Lib "odbc32.dll" _ (ByVal hEnv As Long, _ ByVal fDirection As Integer, _ ByVal szDSN As String, _ ByVal cbDSNMax As Integer, _ ByVal pcbDSN As Integer, _
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
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 we have to send another system
1
1793
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.