[Mono-list] passing MonoArray from c#

fozzie david_aiken at yahoo.com
Fri May 1 23:23:35 EDT 2009

This is the C# code which is called:

    public struct Data
        public int i;

        public System.IntPtr s;

        public float f;

    public struct Link
        public int type;
        public Data data;

    public enum DataType { DT_Int = 0, DT_String = 1, DT_Float = 2 };

    public class Widget : Controller
        public override Link[] Pack(System.UInt32 packFlags)
            Link[] links = new Link[2];
            links[0].type = (int)DataType.DT_Float;
            links[0].data.f = mMass;
            links[1].type = (int)DataType.DT_String;
            links[1].data.s = mName;

            return links; // TBD is this valid until the C++ side is done
with it?

        public override object Invoke(string methodName, object[]
            return this.GetType().InvokeMember(methodName,
BindingFlags.InvokeMethod, null, this, parameters);

This is the calling C++ code.. the debugger output shows that the
Widget:Pack call gets the packFlags parameter correctly and exits:

        typedef enum {DT_Int = 0, DT_String = 1, DT_Float = 2} DataType; //
has to match type in Controllers.cs

        typedef union 
            int i;
            WCHAR *s;
            float f;

        typedef struct
            int type;
            Data data;

        MonoArray *args = mono_array_new(domain, mono_get_object_class(),
        MonoObject *result = mono_value_box (domain, mono_get_uint32_class
(), &packFlags);
        mono_array_setref (args, 0, result);
        MonoObject *retVal = mMonoClass->invoke("Pack", args);
        MonoArray *retLinks = (MonoArray *)mono_object_unbox(retVal);

        mono_object_unbox (MonoObject *obj)
        	/* add assert for valuetypes? */
        	g_assert (obj->vtable->klass->valuetype);
        	return ((char*)obj) + sizeof (MonoObject);

Unfortunately the assert is triggered since valuetype is 0. I'm not sure
that i'm handling the WCHAR*/IntPtr properly, but it seems there is another
issue. Any help appreciated!
View this message in context: http://www.nabble.com/passing-MonoArray-from-c--tp23341741p23342751.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list