On Mon Aug 21 06:23:13 2023 +0000, Mohamad Al-Jaf wrote:
I remembered that there was an MR that wanted to add dxcore for MinGW, but I don't personally use MinGW myself. I tried adding the template wrappers using cpp_quote but the built header had them outside the interface block.
[ local, object, uuid(526c7776-40e9-459b-b711-f32ad76dfc28), ] interface IDXCoreAdapterList : IUnknown { HRESULT GetAdapter(uint32_t index, REFIID riid, [out, iid_is(riid)] void **ppv); uint32_t GetAdapterCount(); BOOL IsStale(); HRESULT GetFactory(REFIID riid, [out, iid_is(riid)] void **ppv); HRESULT Sort(uint32_t num_preferences, const DXCoreAdapterPreference *preferences); BOOL IsAdapterPreferenceSupported(DXCoreAdapterPreference preference); cpp_quote("#ifdef __cplusplus") cpp_quote("template<class T> HRESULT STDMETHODCALLTYPE GetAdapter(uint32_t index, T **ppv)") cpp_quote("{") cpp_quote(" return GetAdapter(index, IID_PPV_ARGS(ppvAdapter));") cpp_quote("}") cpp_quote("template <class T> HRESULT GetFactory(T **ppv)") cpp_quote("{") cpp_quote(" return GetFactory(IID_PPV_ARGS(ppv));") cpp_quote("}") cpp_quote("#endif") };
Resulted in:
#ifdef __cplusplus template<class T> HRESULT STDMETHODCALLTYPE GetAdapter(uint32_t index, T **ppv) { return GetAdapter(index, IID_PPV_ARGS(ppvAdapter)); } template <class T> HRESULT GetFactory(T **ppv) { return GetFactory(IID_PPV_ARGS(ppv)); } #endif DEFINE_GUID(IID_IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7,0x11, 0xf3,0x2a,0xd7,0x6d,0xfc,0x28); #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("526c7776-40e9-459b-b711-f32ad76dfc28") IDXCoreAdapterList : public IUnknown { virtual HRESULT STDMETHODCALLTYPE GetAdapter( uint32_t index, REFIID riid, void **ppv) = 0; virtual uint32_t STDMETHODCALLTYPE GetAdapterCount( ) = 0; virtual BOOL STDMETHODCALLTYPE IsStale( ) = 0; virtual HRESULT STDMETHODCALLTYPE GetFactory( REFIID riid, void **ppv) = 0; virtual HRESULT STDMETHODCALLTYPE Sort( uint32_t num_preferences, const DXCoreAdapterPreference *preferences) = 0; virtual BOOL STDMETHODCALLTYPE IsAdapterPreferenceSupported( DXCoreAdapterPreference preference) = 0; };
I didn't see a way around it without manually hard-coding the lines for C++, which was not worth it at that point.
Microsoft's `<unknwn.idl>` actually has similar C++ helpers for `IUnknown`, emitted using `cpp_quote()`. What they end up doing is, they emit the entire interface twice: once manually with the C++ helpers, and once generated by the IDL compiler. I don't know if it's worth doing that here.
An alternative is to have `cpp_quote()` emit its literal text inside the interface when it is found inside an interface. But this behavior would diverge from MIDL.