Stack prob. Setting callback in native dll.



I have a 3th party dll writen in C. I have no problem calling most
functions in the dll from the managed code. But there is a function
that take a function pointer for setting a callback function that I am
having problems with.
I have the following code:

First in a wrapper class

[DllImport("w32dll.dll")] static void dllSetCallFp( void
(*aFp)(void*) );

Then in seperate class.

delegate void funDelegate(void*);
typedef void ( *FUNPT)(void*);
funDelegate ^ fp = gcnew funDelegate(MFun);
pin_ptr<funDelegate^> pp = &fp;
IntPtr ip = Marshal::GetFunctionPointerForDelegate(fp);
FUNPT cb = static_cast<FUNPT>(ip.ToPointer());
Wrapper::dllSetCallFp(cb);

MFun is just a test function.

void Client::MFun(void* pV)
{
int i = 9;
}

The problem is I can debug into the calling of MFun but when I return I
get the following errors
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.
Then
'FatalExecutionEngineError'

.



Relevant Pages

  • Re: Stack prob. Setting callback in native dll.
    ... static void dllSetCallFp(void (*aFp)); ... The problem is I can debug into the calling of MFun but when I return I ... with a different calling convention. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Stack prob. Setting callback in native dll.
    ... delegate(i.e., modopt) using ildasm ... static void dllSetCallFp(void (*aFp)); ... The problem is I can debug into the calling of MFun but when I return I ... with a different calling convention. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: print "foo" without using ;
    ... The main reason that an OS (or other calling environment) wouldn't accept a void function, rather than an function returning int is that the calling convention is incompatible. ...
    (comp.lang.c)
  • Re: Memory Leak Experts!!!!
    ... Implementing the dispose design pattern (i.e. implementing the ... IDisposable interface in .NET and calling .Dispose on your objects) is ... managed code is solely handled by the framework, ... >> Regards, ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Calling MAPI from C++/CLI
    ... of support for calling MAPI methods from managed code. ... to move my code toward calling the Outlook Object Model ... call unmanaged code directly from managed code. ...
    (microsoft.public.win32.programmer.messaging)