From ff53b8efce55f5668af61f13b656fdb54dee7755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 19 Jul 2022 17:26:24 +0200 Subject: Check Windows API calls for errors more consistently. Some of the checks are likely redundant, but the Windows API documentation rarely makes it clear WHICH errors may be returned (and under which circumstances) rather than simply WHETHER errors may be returned (under any circumstances, including those that do not apply in the given case). --- c/common.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'c/common.cpp') diff --git a/c/common.cpp b/c/common.cpp index ba6593b..b85be49 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -61,7 +61,7 @@ Library::~Library() } /* Move message box to center of main window. */ -static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPARAM lParam) +static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPARAM lParam) noexcept { extern HWND g_hWnd; if (!g_hWnd || nCode < 0 || nCode != HCBT_ACTIVATE) @@ -87,10 +87,8 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR int EBMessageBox(const TCHAR* const tszText, const TCHAR* const tszCaption, const unsigned uType) { extern HWND g_hWnd; - HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); - if (!hHook) return 0; + HHOOK hHook = throw_nil(WH_CBT, CBTProc, (HINSTANCE)NULL, GetCurrentThreadId()); int r = MessageBox(g_hWnd, tszText, tszCaption, uType); - UnhookWindowsHookEx(hHook); - if (!hHook) throw Win32Error(GetLastError()); + throw_nil(hHook); return r; } -- cgit v1.2.3