[Mono-list] mono_method_get_unmanaged_thunk

Robert Jordan robertj at gmx.net
Sat Jun 21 11:42:53 EDT 2008


Robert Jordan wrote:
> Robert Jordan wrote:
>> Andrius Bentkus wrote:
>>> Robert Jordan wrote:
>>>> mono_get_delegate_invoke () expects a delegate class as an
>>>> argument:
>>>>
>>>> static void*
>>>> gimme (MonoDelegate * obj)
>>>> {
>>>>      MonoMethod * method =mono_get_delegate_invoke (
>>>> 	mono_object_get_class ((MonoObject*)obj));
>>>> }
>>>>
>>> This wont work, but i used the code from  
>> The code above definitely works for me.
>>
>>> http://www.nabble.com/file/p18043758/libtest.c libtest.c  and 
>>> http://www.nabble.com/file/p18043758/thunks.cs thunks.cs  which i found in
>>> the /mono/tests directory in the revision of mono you told me to use.
>>> It seems to me that mono_method_get_unmanaged_thunk requires a function
>>> handle instead of a monomethod. 
>> Nope. It needs a MonoMethod*.
> 
> I've corrected your code:

And now even with exception handling ;-)


extern gpointer mono_method_get_unmanaged_thunk (MonoMethod *method);


typedef void (*VoidFunction) (MonoDelegate *, MonoException **);

static void*
gimme (MonoDelegate * obj)
{
     MonoException* ex;
     MonoMethod * method = 
mono_get_delegate_invoke(mono_object_get_class ((MonoObject*)obj));
     VoidFunction MyFunction = mono_method_get_unmanaged_thunk (method);
     MyFunction (obj, &ex);
     if (ex)
	    printf ("got an exception!\n");
}

Robert



More information about the Mono-list mailing list