From 3a8d7270b2eeaab9884eacc012ec968ba0b2da06 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 6 Jun 2020 13:41:58 +1000 Subject: Add ReleaseUnknown to safely release IUnknown* and avoid warnings when done in noexcept context. --- win32/PlatWin.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'win32/PlatWin.h') diff --git a/win32/PlatWin.h b/win32/PlatWin.h index 58ba5e78f..0d1c99b48 100644 --- a/win32/PlatWin.h +++ b/win32/PlatWin.h @@ -57,6 +57,23 @@ T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept { return fp; } +// Release an IUnknown* and set to nullptr. +// While IUnknown::Release must be noexcept, it isn't marked as such so produces +// warnings which are avoided by the catch. +template +void ReleaseUnknown(T *&ppUnknown) noexcept { + if (ppUnknown) { + try { + ppUnknown->Release(); + } + catch (...) { + // Never occurs + } + ppUnknown = nullptr; + } +} + + UINT DpiForWindow(WindowID wid) noexcept; int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept; -- cgit v1.2.3