Recipe and best practice for accessing COM

newToCOM new at to.com
Sun Sep 9 06:25:13 PDT 2012


> In this example the pID2D1Factory is a void*, so it will need a 
> cast to the proper type with a cast(ID2D1Factory) soemtime 
> after the create call;
>
> Since this particular API takes an out void* (since it is 
> capable of creating multiple unrelated types), it would need to 
> look something like this:
>
> HRESULT hr = D2D1CreateFactory(
>     D2D1_FACTORY_TYPE.SINGLE_THREADED,
>     pIID_ID2D1Factory,
>     pfactoryOptions,
>     pID2D1Factory);
>
> if (SUCCEEDED(hr))
> {
> 	assert(pID2D1Factory !is null);
> 	ID2D1Factory factory = cast(ID2D1Factory)pID2D1Factory;
> 	factory.GetDesktopDpi(dpiX, dpiY);
> }
>
>
> I've been super busy at work so haven't had much time to 
> respond to this thread.
>
>
> Technically the API's fourth argument could be rewritten to be 
> an 'out IUnknown', but then you are stuck calling 
> QueryInterface, and back to having the exact same problem with 
> the QueryInterface method.


Thanks a lot! That solved my issue.


More information about the Digitalmars-d-learn mailing list