[Mono-list] mono embedding in c++: how to get a array from C# code?

Jonathan Mitchell jonathan at mugginsoft.com
Mon Nov 9 10:04:23 UTC 2015

> On 9 Nov 2015, at 00:22, sunsflower <ssfxtr at outlook.com> wrote:
> and how can I pass a pointer to mono?...
> <code>
> stuct test
> {
>        int index;
>        string name;
> };
> MonoMethod* method = mono_class_get_method_from_name(klass, "testfunc", 2);
> MonoException* ex;
> typedef int(__stdcall *func)(MonoObject*, test*, MonoException**);
> func f1 = (func)(mono_method_get_unmanaged_thunk(method));
> test t1;
> </code>
> something like this? but C# won't accept a pointer except in unsafe context.
> is there some other way of doing this - to read from a pointer to a struct
> in C# and change it? or should I just pass the struct as a value?
I am not quite sure what your intention is here.
The managed struct is of course a value type.
Try passing your struct reference like so (MonoObject *)&x
I think that a struct returned by a method is a MonoObject * that you can access using normal field and property accessors.

If curious, you could glance at the following - it’s Obj-C not C++ but it might help.

I agree that Mono is great but the embedded API is quite opaque and the headers and overall level of documentation is minimalist to say the least.
It does make for quite a steep learning curve but the community is genuinely helpful.

More information about the Mono-list mailing list