Interfacing with XPCOM

John Reimer terminal.node at gmail.com
Tue Dec 2 17:01:16 PST 2008


Hello Walter,

> John Reimer wrote:
> 
>> In D (windows) it would look like so (assuming you have done away
>> with the compilers internal detection of COM interfaces):
>> 
>> extern(C++) interface IUnknown:
>> {
>> extern(Windows):
>> int QueryInterface(nsIID* uuid, void **result);
>> int AddRef();
>> int Release();
>> }
>> I bet it would work fine and would be a good way to avoid the
>> special-cased interfaces providing COM support in D.  Instead we've
>> special-cased for C++, which is, at least, a more general case. ;-)
>> 
> There is one other problem. COM objects are not collected by the
> garbage collector because they are reference counted. Deriving from
> IUnknown means its a COM object which sets a flag in the ClassInfo,
> directing the garbage collector to not collect it. In fact, COM
> objects are allocated using malloc(). IUnknown.Release() uses free()
> to deallocate them.
> 


Okay, that is an important detail for me to know.  But I assumed that a C++ 
interface must not be allocated in D either.  In must acquire a pointer from 
an external factory that handles the allocation outside of the gc range (C++ 
code must allocate/delete it's own objects).

This seems to me to be a somewhat equivalent process as for a COM object.

Is there a ClassInfo flag indicating no-gc-collection for extern(C++) interfaces 
too?

-JJR





More information about the Digitalmars-d mailing list