[Mono-list] internal calls and advanced bindings in C++
Robert Jordan
robertj at gmx.net
Sun Dec 31 10:39:21 EST 2006
virgile.bello at free.fr wrote:
> Hi,
>
> In my quest to do bindings between Mono and C++ (compile&runtime generated on
> C++ side due to varying implementation of how C++ calls function), I realized
> that it would be hard to do it with only internal calls cdecl function that
> could only be compile-time generated.
> To switch to runtime generation of function dispatching, it would require
> metadata such as an integer (index) or pointer to be put on the stack of the
> manager to native wrapper.
> An example of what I would need would be :
>
> void mono_add_internal_call_with_param( const char *name, gconstpointer method,
> void* param1 );
> that would call method( void* param1, MonoObject* MonoParam1, MonoObject*
> MonoParam2, ... );
> First, I'd like to know what you think about such a proposal, would it be
> usefull for some of you ?
> Where would be the cleanest place to implement it ?
> Of course I'm up to work on it as needed.
> I think that I will code it anyway, but if it can help someone else, and fit in
> the main tree it would be even better.
If I understand correctly you're automatically generating the
managed wrappers. It this case you could easily store your context
in the generated wrapper itself, i.e. as a IntPtr:
C#:
public class WrapperForCppClassFoo {
static IntPtr yourCookie;
public void SomeCppMethod (int arg)
{
SomeCppMethodInternal (yourCookie, this, arg);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void SomeCppMethodInternal
(IntPtr cookie, object thisObj, int arg);
}
C++:
void SomeCppMethodICall (void *cookie, MonoObject* obj, int arg)
{
...
}
Another way (get the cookie from the static field directly)
C#
public class WrapperForCppClassFoo {
static IntPtr yourCookie;
[MethodImpl(MethodImplOptions.InternalCall)]
public extern void SomeCppMethod (int arg);
}
C++:
void SomeCppMethodICall (MonoObject* obj, int arg)
{
/* obtain the `yourCookie' field from the class of `obj' */
}
Robert
More information about the Mono-list
mailing list