[Mono-list] mono embedding in c++: how to get a array from C# code?
Jonathan Mitchell
jonathan at mugginsoft.com
Sun Nov 8 13:13:36 UTC 2015
> On 8 Nov 2015, at 02:41, sunsflower <ssfxtr at outlook.com> wrote:
>
> I've tried to use a monoclassfield but it doesn't work with a string array in
> C#. the return value is invalide.
> c++:
> <code>
> MonoClassField* field;
> field = mono_class_get_field_from_name(klass, "entry");
> char* val[100];
> MonoString* monoval[100];
> mono_field_get_value(obj, field, monoval);
> val[0] = mono_string_to_utf8(monoval[0]);
> </code>
>
I reckon that mono_field_get_value will return a MonoArray,
Try something a bit like this:
MonoArray* monoArray = NULL;
mono_field_get_value(obj, field, monoArrayl);
MonoString *monoString = mono_array_get(monoArray, MonoString *, 0)
char *s = mono_string_to_utf8(monoString); // copy this into a buffer that you manage
mono_free(s);
J
More information about the Mono-list
mailing list