core.sys.windows.com.ComObject apparently has wrongly laid out Vtable
Carl Sturtivant
sturtivant at gmail.com
Thu Mar 21 13:22:34 UTC 2024
On Thursday, 21 March 2024 at 03:48:04 UTC, Walter Bright wrote:
> On 3/20/2024 7:38 AM, Carl Sturtivant wrote:
>> So why isn't ComObject declared extern(C++) in druntime?
>
> Because COM objects need to follow the extern(Windows) calling
> convention. It's a mistake to try to cast it to extern(C++).
>
> I didn't invent this. Microsoft did. COM was invented around
> 1990 or so. It's cast in concrete.
I was hoping that the special treatment by the D language of
IUnknown in core.sys.windows.com would apply to any class that
inherited from it, even an extern(C++) class, so I could have my
cake and eat it, and
```D
extern(C++) class ComObject : IUnknown { /* ... */ }
```
would produce a class with extern(Windows) calling and an
extern(C++) COM compatible vtable.
This does compile. Does the extern(C++) remove the special
treatment of IUnknown and revert the class to the wrong calling
convention?
More information about the Digitalmars-d
mailing list