core.sys.windows.com.ComObject apparently has wrongly laid out Vtable
Carl Sturtivant
sturtivant at gmail.com
Wed Mar 20 14:11:02 UTC 2024
Now here's the new ComObject class, identical to that in druntime
apart from the necessary `com.` prefix due to the static import
of `core.sys.windows.com`, except that I declared the class
extern(C++).
```D
import com = core.sys.windows.com;
import windows = core.sys.windows.windows;
import core.atomic;
extern(C++) class ComObject : com.IUnknown
{
HRESULT QueryInterface(const(com.IID)* riid, void** ppv)
{
if (*riid == com.IID_IUnknown)
{
*ppv = cast(void*)cast(com.IUnknown)this;
AddRef();
return S_OK;
}
else
{ *ppv = null;
return com.E_NOINTERFACE;
}
}
ULONG AddRef()
{
return atomicOp!"+="(*cast(shared)&count, 1);
}
ULONG Release()
{
LONG lRef = atomicOp!"-="(*cast(shared)&count, 1);
if (lRef == 0)
{
// free object
// If we delete this object, then the postinvariant
called upon
// return from Release() will fail.
// Just let the GC reap it.
//delete this;
return 0;
}
return cast(ULONG)lRef;
}
LONG count = 0; // object reference count
}
```
So this ComObject inherits from the druntime interface IUnknown
and according to the docs therefore has extern(System) as its
default for methods, which is extern(Windows) here.
More information about the Digitalmars-d
mailing list