[MIDL]How to use interfaces declared in c/c++ headers in idl files?

1.2k views Asked by At

ID2D1RenderTarget is an interface defined in d2d1.h. I want to use it in my IDL interface like this:

interface IXXX : IUnknown {
    HRESULT XXX([out, retval] ID2D1RenderTarget **_ppRT);
}

d2d1.idl is not included in the SDK and I can only get d2d1.h(no d2d1.tlb, either).

I have tried including d2d1.h using cpp_quote:

cpp_quote("#include <d2d1.h>")

It raised:

error MIDL2025: syntax error : expecting a type specification near "ID2D1RenderTarget"

Then I added a typedef:

typedef struct ID2D1RenderTarget ID2D1RenderTarget;

The error changed to this:

error MIDL2011: unresolved type declaration : ID2D1RenderTarget [ Type 'ID2D1RenderTarget' ( Parameter '_ppRT' ) ]

I have also tried adding cpp_quote("#define D2D_USE_C_DEFINITIONS") before the include but it made nothing.

So what should I do to use ID2D1RenderTarget in my IDL files?

1

There are 1 answers

0
Roman Ryltsov On BEST ANSWER

MIDL compiler needs an IDL file to refefence, or a type library. Direct2D interfaces are not available any of these methods. They are not available through registered type library either - you only have them as C++ headers in Windows SDK.

One way would be to duplicate definitions in your IDL/TLB file, however I would recommend to accept the fact that interfaces are undefined in IDL domain and use IUnknown there instead. A type library consumer can always do IUnknown::QueryInterface for the interface in question.

interface IXXX : IUnknown 
{
    HRESULT XXX([out, retval] IUnkown** ppRendererTargetUnknown);
}