[Mono-list] Invoking Method from Native Code

Paolo Molaro lupus@ximian.com
Wed, 20 Aug 2003 16:06:47 +0200


On 08/19/03 Hamza Karamali wrote:
> If I have the following code in mono:
> 
> 	MonoMethod *someMethod
> 	
> 	...
> 	...
> 
> 	gpointer myMethod;
> 	myMethod = mono_jit_compile_method(someMethod);
> 	
> Is there an easy way that I can just invoke the compiled method from
> withing the mono code if it's a simple method that doesn't have any
> arguments?

You may do a cast:

typedef void (*VoidFunc)(void);

	VoidFunc my_func = (VoidFunc)myMethod;
	my_func ();

but be aware that this way is not supported (since it doesn't take care
of exceptions and the unmanaged->managed transition) so it shouldn't be
used in production code.
The correct way is to call (if you want to just ignore exceptions):

	mono_runtime_invoke (someMethod, NULL, NULL, NULL);

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better