[Mono-dev] Embedding + GObject Subclasses

Christian Hoff christian_hoff at gmx.net
Thu Sep 3 15:48:09 EDT 2009


Matthew Metnetsky wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Christian Hoff wrote:
>   
>>> Suppose I had the following class:
>>>
>>> class Foo : Gtk.Box
>>> {
>>>   public new int Spacing {
>>>     Console.WriteLine("HI");
>>>     return base.Spacing;
>>>   }
>>> }
>>>
>>> which is compiled into Foo.dll. Is there a way from within a native
>>> application to instantiate Foo via it's GType like:
>>>
>>> GObject * o = g_object_new(FooType, NULL);
>>>   
>>>       
>> I'm not 100% sure if that works; just give it a try. FooType can only be
>> obtained by calling managed code (FooType = (Glib.GType) Foo).
>>     
>
> I'm not quite following you here. How are you suggesting I go about
> getting FooType within C?
>   
Sorry, I meant calling FooType = (Glib.GType) typeof (Foo) will give you 
the GType. There is no way to get FooType by only using C code, but you 
could make sure that this line of code is onvoked by your managed 
application first, which could then pinvoke a func in Foo.dll and pass 
the GType to it:

[DllImport ("Foo.dll")]
static extern void foo_set_gtype (IntPtr type);
[...]
GLib.GType FooType = (Glib.GType) typeof (Foo);
foo_set_gtype (FooType.Val);

Only after this code has been run on the managed side, you will be able 
to use FooType.

Christian


More information about the Mono-devel-list mailing list