aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.h
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-06-06 13:41:58 +1000
committerNeil <nyamatongwe@gmail.com>2020-06-06 13:41:58 +1000
commit3a8d7270b2eeaab9884eacc012ec968ba0b2da06 (patch)
tree733529258b61908315d39fbceeff54406c6f075b /win32/PlatWin.h
parent1be0995e0ee4ec69426ae908ae8d05603dfaa905 (diff)
downloadscintilla-mirror-3a8d7270b2eeaab9884eacc012ec968ba0b2da06.tar.gz
Add ReleaseUnknown to safely release IUnknown* and avoid warnings when done in
noexcept context.
Diffstat (limited to 'win32/PlatWin.h')
-rw-r--r--win32/PlatWin.h17
1 files changed, 17 insertions, 0 deletions
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 <class T>
+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;