F
FrankVDL
Hi,
I have some problems executing a method using P/Invoke in my C# 2.0
app.
This is the definition for the original .H file
LDVCode LDVAPI ldv_read(
IN LdvHandle handle, /* session handle (from ldv_open) */
OUT PVOID msg_p, /* pointer to buffer to receive message */
IN SHORT len /* length of buffer to receive message */
);
This is how I translated it to C#
[DllImport("ldv32.dll")]
private static extern short ldv_read(short handle, out IntPtr msg_p,
short len);
The error occurs when i try to read data :
err = (LdvError)ldv_read(_LdvHndl, out ptr, (short) 255);
byte[] buf = new byte[255];
Marshal.Copy(ptr, buf, 0, 255);
This is the exception:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often
an indication that other memory is corrupt."
Source="mscorlib"
What am I doing wrong ?
I have some problems executing a method using P/Invoke in my C# 2.0
app.
This is the definition for the original .H file
LDVCode LDVAPI ldv_read(
IN LdvHandle handle, /* session handle (from ldv_open) */
OUT PVOID msg_p, /* pointer to buffer to receive message */
IN SHORT len /* length of buffer to receive message */
);
This is how I translated it to C#
[DllImport("ldv32.dll")]
private static extern short ldv_read(short handle, out IntPtr msg_p,
short len);
The error occurs when i try to read data :
err = (LdvError)ldv_read(_LdvHndl, out ptr, (short) 255);
byte[] buf = new byte[255];
Marshal.Copy(ptr, buf, 0, 255);
This is the exception:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often
an indication that other memory is corrupt."
Source="mscorlib"
What am I doing wrong ?