COM Expertise needed: COM Callbacks
Nierjerson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 28 16:31:08 PDT 2017
On Friday, 28 April 2017 at 09:25:31 UTC, John Chapman wrote:
> On Thursday, 27 April 2017 at 20:20:23 UTC, Nierjerson wrote:
>>
>
> QueryInterface is COM's version of opCast. It asks if you
> support the interface represented by an IID (riid). If you
> don't, then you return E_NOINTERFACE. If you do, then you point
> the result (pvObject) to yourself and return S_OK. Here's a
> basic implementation:
>
> extern(Windows)
> HRESULT QueryInterface(IID* riid, void** pvObject) {
> if (pvObject is null) return E_POINTER;
> *pvObject = null;
>
> if (*riid == IID_IUnknown) *pvObject =
> cast(void*)cast(IUnknown)this;
> else if (*riid == IID_IDispatch) *pvObject =
> cast(void*)cast(IDispatch)this;
> // and so on for all interfaces we support
>
> if (*pvObject is null) return E_NOINTERFACE;
> (cast(IUnknown)this).AddRef();
> return S_OK;
> }
>
Your code works. I had something similar but I think I was
returning a null pointer on IID_Unknown or something similar. I
now get a different error but it is a COM error rather than
access violation. (error 80020009)
More information about the Digitalmars-d-learn
mailing list