[Mono-list] embedding mono and returning GList

Miguel de Icaza miguel at xamarin.com
Sun May 22 09:48:19 EDT 2011

> I'd like to call a managed method from c which returns a GLib.List.
> I seem to be unable to do this,  however..
> my managed code looks like:
> public GLib.List Test()
>  {
>         GLib.List list = new GLib.List(typeof(string));
>         list.Append("eins");
>         list.Append("zwei");
>         list.Append("drei");
>         list.Append("vier");
>         return list;
>  }
> my unmanaged code looks like:
> MonoObject *o = mono_runtime_invoke (method, instance, NULL, &ex);
> GList *list = (GList *)o;

That is because the managed GList object is merely a wrapper around the real

What you are getting back is not a pointer to the C GList, but a pointer to
the managed GList;   What you need to do is return the unmanaged pointer
that is wrapped by the C# GList, that would be the GList.Handle.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110522/fdcfb36d/attachment-0001.html 

More information about the Mono-list mailing list