core.sys.windows.com.ComObject apparently has wrongly laid out Vtable

Walter Bright newshound2 at digitalmars.com
Thu Mar 21 16:06:32 UTC 2024


On 3/21/2024 6:22 AM, Carl Sturtivant wrote:
> 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?
> 
> 

The C++ and Windows calling convention are different. COM code will not be able 
to successfully call C++ functions. You can derive a C++ class from a COM 
interface, but you can't cast a COM interface to a C++ class.


More information about the Digitalmars-d mailing list