Skip to content

Working with IMonoMethod

RoqueDeicide edited this page Jan 2, 2015 · 1 revision

IMonoMethod is an interface that provides access to Mono methods. You can use to:

  1. Invoke a method.
  2. Get information about the method.
  3. And finally get the invocable function pointer (also known as unmanaged thunk).

Method details

You can only get the name and parameter count for the method in v1 using properties Name and ParameterCount respectively.

Invocation

IMonoMethod defines two overloads of Invoke function, each using a different way of providing the list of parameters.

Invocation target

Invocation target is an additional object that is passed to Invoke as a first parameter if the function is not static. Interestingly enough, when you invoke a method of a value-type object, you need to provide a pointer to an unboxed instance of one. When function is static, null has to be passed.

Result of invocation

If the function returns a value and it's of value-type, then it will be a boxed instance. If function doesn't return anything the result of Invoke should not be used anywhere.

Parameters

Parameters can be provided with either IMonoArray object or by using a C++ array of pointers to objects. The former is much slower, but is more dynamic, while latter is much faster, but is more static.

Polymorphism

If your method is virtual and you provide true as a last argument for Invoke, then you will perform late-bound invocation of that method, otherwise a method of the type you acquired the method from will be invoked in early-bound fashion.

Unmanaged thunks

Unmanaged thunks are essentially function pointers that you can invoke just like any function. Their definition requires you to follow some very complex rules and you have to do quite a lot of boxing operations, but it is one of the faster ways of invoking a Mono function.

Examples

Consult Doxygen-style documentation of IMonoMethod in IMonoInterface.h for some very detailed examples of code.