title: Compatibility of GObject and COM object models
body: <p><a href="http://en.wikipedia.org/wiki/GObject" rel="nofollow noreferrer">GObject</a> implements objects in plain C by using a handful of conventions: Static methods are just functions taking the instance struct as first argument. Virtual methods are implemented as function pointers in a class struct (a kind of vtable). You can have inheritance by placing a <a href="https://stackoverflow.com/a/1114360/143091">parent class struct in the child class struct</a>, and so on.</p>
  
  <p>COM is a different object system, used in Windows, and <a href="http://blogs.msdn.com/b/oldnewthing/archive/2004/02/05/68017.aspx" rel="nofollow noreferrer">designed to coincide with C++'s memory layout</a> (at least with the MSVC compiler). Objects have a vtable, to which you can get an interface pointer, and then you can call the methods of the object. The calling convention used is very similar (identical?) to the one described above, you pass the instance pointer as first argument.</p>
  
  <p>Now, I'm wondering, <strong>is it possible to make a GObject class/object that would also be valid in COM?</strong> I'm thinking by e.g. placing a pointer to the class struct in the beginning of the instance struct, and writing some glue code. Would I then be able to QueryInterface a pointer to my GObject subclass and call virtual methods on it?</p>
  
  <p>If it would work, could you outline how?</p>
  
  <p>If it wouldn't work, what are the differences in the object system making it impossible?</p>