[Mono-dev] Internal-Call

Dexter Yao yyao1985320 at gmail.com
Tue Dec 8 20:49:14 EST 2009


Having read all the embeded and script features of mono, I want to use C#
instead of Lua as the script language while the host language is C++ in my
project.
I want to use C#( managed code ) to call the functions which exposed from
C++ using internal-call approach, and i want to call the instance method(
C++ ) also. But i tried and read all the material, i can't resolve it.
Only find one way that is use another internal-call to received a pointer of
a object, here is the example.

//******************* C++ *******************
...
class SimpleClass
{
	...
public:
	Hello( ) { printf( "Hello" ); }
	...
}

void testcall( SimpleClass *sc )
{
	return sc->Hello( );
}
...
int main( int argc, char* argv[] )
{
	...
	mono_add_internal_call( "Embed.MyType::testcall", ( const void* )testcall
);
	...

	SimpleClass sc;
	args[0] = ≻
	mono_runtime_invoke( method, obj, args, NULL );
}

//******************* C# ********************
...
class MyType
{
	[MethodImplAttribute( MethodImplOptions.InternalCall )]
	public static extern void testcall( ref IntPtr p );
	...

	void SomeMethod( ref IntPtr p )
	{
		...
		testcall( ref p );
		...
	}
}
...

Is there a another better way to call from C#( managed code ) by passing the
pointer( IntPtr in C# ) of one C++ object and invoke its method? ( like the
Lua does )
Looking forward to your reply.
-- 
View this message in context: http://old.nabble.com/Internal-Call-tp26691444p26691444.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list