From 876871f0391de2730ac7562491d5cffb5fdd9ed1 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 11 Feb 2025 19:13:59 +1100 Subject: Update Direct2D and DirectWrite functions and types to Direct2D 1.1. --- win32/WinTypes.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'win32/WinTypes.h') diff --git a/win32/WinTypes.h b/win32/WinTypes.h index 9badd70a8..9c930bb7c 100644 --- a/win32/WinTypes.h +++ b/win32/WinTypes.h @@ -38,6 +38,24 @@ struct UnknownReleaser { } }; +// Wrap COM IUnknown::QueryInterface to produce std::unique_ptr objects to help +// ensure safe reference counting. +template +inline HRESULT UniquePtrFromQI(IUnknown *source, REFIID riid, std::unique_ptr &destination) noexcept { + T *ptr{}; + HRESULT hr = E_FAIL; + try { + hr = source->QueryInterface(riid, reinterpret_cast(&ptr)); + } catch (...) { + // Shouldn't have exceptions from QueryInterface but not marked noexcept + } + if (SUCCEEDED(hr)) { + destination.reset(ptr); + } else { + destination.reset(); + } + return hr; +} /// Find a function in a DLL and convert to a function pointer. /// This avoids undefined and conditionally defined behaviour. -- cgit v1.2.3