Interfacing with XPCOM

Denis Koroskin 2korden at gmail.com
Tue Dec 2 04:07:25 PST 2008


On Tue, 02 Dec 2008 13:23:55 +0300, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> 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.

Well, C++ objects shouldn't be garbage-collected either, should they?



More information about the Digitalmars-d mailing list