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

Carl Sturtivant sturtivant at gmail.com
Wed Mar 20 14:38:11 UTC 2024


On Wednesday, 20 March 2024 at 14:26:24 UTC, Carl Sturtivant 
wrote:
> Note that I cast COMobject (which is a new ComObject) directly 
> to a IUnknown*. (Here IUnknown is the struct defined in 
> `comdef.c` just the way Windows defines it.) This code works! 
> This shows that the Vtable of the extern(C++) ComObject has COM 
> interface layout. However, if I remove `extern(C++)` from the 
> definition of the new ComObject class, now this does NOT work.

So ComObject in core.sys.windows.com (in druntime) is actually 
NOT a COM object in the external world of COM sense. But if was 
to be declared extern(C++) it would be a COM object in that 
sense, directly castable to an external IUnknown* that works 
externally, or so it seems.

The only possible snag might be calling conventions for its 
methods. However, it inherits from the druntime D interface 
IUnknown which supposedly guarantees the correct convention for 
Windows/COM.

So why isn't ComObject declared extern(C++) in druntime?




More information about the Digitalmars-d mailing list