[Mono-dev] passing references to managed objects to unmanaged code

Andreas Lagemann ae at Informatik.tu-Cottbus.DE
Tue Feb 6 06:00:32 EST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,
I am trying to pass a reference to a managed object to unmanaged code
where I would like to handle it like a MonoObject, so I could use the
momo_embed API to call methods of the managed object from unmanaged code.

What I have in mind is some kind of C#/C++ peership where each C#
instance of a certain Object has a C++ peer object and the other way round.

I tried something like this:

C#:
...
[DllImport("Simkernel",EntryPoint="SetCsharpPeer")]
  public static extern void MyClass_SetCsharpPeer(
	HandleRef jarg1,
	[MarshalAs(UnmanagedType.Struct)]HandleRef jarg2
	)
...

MyClass::SetCsharpPeer(MonoObject* object)
{
	csharpPeer = Object;
	...
}

after calling SetCsharpPeer I try something like;
...

 MonoClass* klass = mono_object_get_class(csharpPeer);
 MonoMethod *m = NULL;
 gpointer iter = NULL;
 while((m = mono_class_get_methods (klass, &iter))) {
	...
 }
...
which results in SEGFAULT when calling mono_class_get_methods.

I did not find anythig about how a csharp object should be marshalled to
access it as a MonoObject in unmanaged code. So UnmanagedType.Struct was
the best guess but since it does not seem to work i obviously have guessed
wrong. 

Is there any way to do what I intend? If so, could anyone please point out how
to do this or tell me where to learn about it?

Thanks for your help and best regards,

Andreas




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFyF/PNfV8qlW7iaERAl7tAJ9R2JJvoq1//dVp8AbFG/NAJ9PoGACgjJWi
lrkxs9a9Yt76hokrA+A0gTw=
=ww7I
-----END PGP SIGNATURE-----



More information about the Mono-devel-list mailing list