COM/OLE advanced questions

Kagamin spam at here.lot
Fri Nov 3 10:50:27 UTC 2017


On Thursday, 2 November 2017 at 14:22:56 UTC, Guillaume Piolat 
wrote:
> Question 1. Is it mandatory to inherit from 
> core.sys.windows.unknwn.IUnknown, or just having an interface 
> named "IUnknown" validate it for being a COM interface?
>
>    If yes, then how am I supposed to use COM interfaces in 
> other OSes? core.sys.windows.unknwn.IUnknown is defined under 
> version(Windows).

I suppose you will need a bunch of definitions. One strange thing 
is that core.sys.windows defines GUID with alignment 1, which I 
expect to differ on other platforms.

>    I wonder what the exact compiler hook is.

I only looks at the name.

> Question 2. If this fails, may I emulate COM vtable layout with 
> extern(C++) class? I wonder what the exact differences are 
> anyway between extern(C++) and the special IUnknown.

Depends on implementation. XPCOM uses straight C++ ABI on linux, 
so look what you want to work with.

> Question 3. It seems I can inherit both from A D object and a 
> COM interface. What will be the choosen layout?

Shouldn't matter, interface defines ABI, how it's implemented is 
irrelevant - that's the very idea behind COM. It's actually legal 
to implement interfaces with composition, the caller still 
doesn't see anything.


More information about the Digitalmars-d-learn mailing list