[Mono-dev] storing references to mono-objects in C++ and passing them back to C#
joncham at gmail.com
Mon Mar 19 10:56:02 EDT 2007
On 3/18/07, Andreas Lagemann <ae at informatik.tu-cottbus.de> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Hi Jonathan,
> Thanks for the prompt answer!
> I played a little with your advice and did work it out. :)
> Jonathan Chambers wrote:
> > Hi Andreas,
> > It sounds like what you are doing is embedding mono. Did you see
> > this page on the wiki (http://www.mono-project.com/Embedding_Mono)? To
> > answer your #2 question, I think you want your menthod to be an internal
> > call, rather than a pinvoke. Internal calls do no marshalling, so you
> > will be able to return an object directly. See the samples that ship
> > with mono, or this part of the link above (
> I did read that, but I didn't consider internal calls as a solution
> - -- don't know why!!
> > So, quickly it will look something like...
> > C#:
> > [MethodImplAttribute(MethodImplOptions.InternalCall)]
> > public static extern object getPeerObjectOf(HandleRef jarg1);
> > And your C++ will almost stay the same; I'm not sure but you may need to
> > adjust your use of HandleRef since it will no longer be marshalled like
> > a pinvoke, so you'll be getting a real HandleRef structure.
> It worked by passing an IntPtr instead of HandleRef and making obj
> void* in the C++ code.
> > Also, don't forget if you make the method an instance method rather than
> > static, the C code needs "MonoObject* this_ptr" as the first argument.
> Does that mean that it is possible to use a
> pointer-to-memberfunction as internal call? I thought it had to be
> pure C function calls!
No, it has to be a C function call. I was saying you can make C# instance
methods internal calls, as well as static methods. It's just that you need
to remember to add a MonoObject* argument as the first parameter of your C
function in that case.
Thanks again for your help,
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v126.96.36.199 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> -----END PGP SIGNATURE-----
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list