diff options
author | Neil <nyamatongwe@gmail.com> | 2025-02-11 19:13:59 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-02-11 19:13:59 +1100 |
commit | 876871f0391de2730ac7562491d5cffb5fdd9ed1 (patch) | |
tree | 3c2e1d6572b56f8e11bdb4f16da284cd3e1e78a5 /win32/WinTypes.h | |
parent | f2e9767e7aa2f3e012f46bf1c5f8b41872051bf0 (diff) | |
download | scintilla-mirror-876871f0391de2730ac7562491d5cffb5fdd9ed1.tar.gz |
Update Direct2D and DirectWrite functions and types to Direct2D 1.1.
Diffstat (limited to 'win32/WinTypes.h')
-rw-r--r-- | win32/WinTypes.h | 18 |
1 files changed, 18 insertions, 0 deletions
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<typename T> +inline HRESULT UniquePtrFromQI(IUnknown *source, REFIID riid, std::unique_ptr<T, UnknownReleaser> &destination) noexcept { + T *ptr{}; + HRESULT hr = E_FAIL; + try { + hr = source->QueryInterface(riid, reinterpret_cast<void **>(&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. |