[Mono-list] Mono 2.2 - P/Invoke - GetFunctionPointerForDelegate assertion
Ben Henderson
bhenderson at ipswitch.com
Thu Mar 19 16:36:21 EDT 2009
Hello all,
I am having an interesting problem with Mono 2.2 with trying to pass a
native function pointer to a function in the same native library. The
sample code below works with the .NET CLR, but dies in the mono runtime with
the following assertion/error (I have also tried changing the prototype for
the P/Invoke method to use the delegate, but get the same assertion when
calling the method):
**
ERROR:marshal.c:9235:mono_marshal_get_managed_wrapper: assertion failed:
(!mono_
method_signature (method)->pinvoke)
This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
**
So.. my question is... Am I doing something wrong? Is this not supported
in mono? Is there a workaround for mono (other than LoadLibrary/dlopen) --
I would like to utilized managed code to do this and not have to add #if's
for different platforms!
Thanks in advance!
Ben
******* Code *******
TESTDLL.DLL code:
**************
#include "stdafx.h"
#include <stdio.h>
extern "C" void TESTDLL_EXPORT foo()
{
printf("foo!\n");
}
extern "C" void TESTDLL_EXPORT bar(void (*fn)(void))
{
if (fn)
{
fn();
}
}
Test Program code:
***************
using System;
using System.Runtime.InteropServices;
namespace FunctionPointerInterop
{
class Program
{
[DllImport("testdll.dll")]
public extern static void foo();
[DllImport("testdll.dll")]
public extern static void bar(IntPtr foo);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void foo_delegate();
static foo_delegate my_foo_delegate;
static void Main(string[] args)
{
my_foo_delegate = new foo_delegate(foo);
IntPtr ptr =
Marshal.GetFunctionPointerForDelegate(my_foo_delegate);
bar(ptr);
}
}
}
--
View this message in context: http://www.nabble.com/Mono-2.2---P-Invoke---GetFunctionPointerForDelegate-assertion-tp22608410p22608410.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list