Hi!
Are you registering the function with DllImport attribute? Try setting the
calling convention of
this attribute.
To use Cdecl:
[DllImport("DllName.dll", CallingConvention = CallingConvention.Cdecl)]
To use Stdcall:
[DllImport("DllName.dll", CallingConvention = CallingConvention.StdCall)]
Try with one or another.
Juan Wajnerman
-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Russell McClure
Sent: Monday, July 21, 2003 4:09 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] P/Invoke question
I am trying to call a C++ function in a regular Win32 DLL with the following
signature:
bool MyFunc
(
void **ppSER,
void **ppVoid,
bool bSetting
)
The first function is a callback function which I seem to be passing
correctly because it does get invoked. The second parameter gets passed to
the callback as one of its parameters (defined as void*).
The C++ code that uses this function passes the second parameter as:
(void**)(this)
I am using C# and everything works execpt I don't know what to pass for the
second parameter. I first defined it as an IntPtr and passed this.Handle.
Doing that the callback was actually called but on return I got this error:
"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention."
I assume that it is the second parameter that is screwing things up since
the first one (void **ppSER) is the callback and it is being invoked and the
third parameter (bool bSetting) is obviously OK.
So my question boils down to: does anyone know the C# equivalent of the C++
(void**)(this)?
Thanks.
Russ