[Mono-list] mono_method_get_unmanaged_thunk

Robert Jordan robertj at gmx.net
Sat Jun 21 11:37:55 EDT 2008


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:


/* declare this since it's not in the public headers of the last release */
extern gpointer mono_method_get_unmanaged_thunk (MonoMethod *method);


/* fix the signature */
typedef void (*VoidFunction) (MonoDelegate *);

static void*
gimme (MonoDelegate * obj)
{
     MonoMethod * method = 
mono_get_delegate_invoke(mono_object_get_class ((MonoObject*)obj));

     /* VoidFunction* was not correct */

     VoidFunction MyFunction = mono_method_get_unmanaged_thunk (method);
     MyFunction (obj);
}


Robert



More information about the Mono-list mailing list