I'm embedding mono 2.10.8 into my application and have some troubles with functions, registered with mono_add_internal_call
Let's say i have managed method:
internal delegate void Win32ServiceHandler(long statusCode);
internal static class Win32Service
{
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void Test(Win32ServiceHandler handler);
}
it's unmanaged definition:
void icall_TestDelegateCallback(MonoDelegate *ftn) {
LPHANDLER_FUNCTION f = (LPHANDLER_FUNCTION)mono_delegate_to_ftnptr(ftn);
f(SERVICE_CONTROL_STOP);
}
and some code to test:
protected virtual void ServiceHandler(Win32ServiceControl statusCode)
{
Console.WriteLine("here");
}
public void MakeTest()
{
Console.WriteLine("before");
Win32Service.Test(this.ServiceHandlerInternal);
Console.WriteLine("after");
}
I run it from console application and when i call MakeTest(), the output is:
before
here
And application never return.
Actually it is a simplified eexample. In real program i need to pass function pointer as a callback to RegisterServiceCtrlHandler
so stuff like mono_runtime_invoke
(that btw works fine) etc isn't what i need.
The question is what is the proper way to call a function pointer obtained from MonoDelegate? Or is it any other correct way to pass it as a callback?
My platform is Windows 7 x64
No comments:
Post a Comment