diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-19 17:26:24 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-19 17:26:24 +0200 |
commit | ff53b8efce55f5668af61f13b656fdb54dee7755 (patch) | |
tree | 3b5802f9a1ac2b5bc7b32578528659a70c4c1b4c /c/common.cpp | |
parent | 0635058400597e43d698c87caf3d3ca4f802e0bd (diff) | |
download | EpisodeBrowser-ff53b8efce55f5668af61f13b656fdb54dee7755.tar.gz |
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).
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
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<SetWindowsHookEx>(WH_CBT, CBTProc, (HINSTANCE)NULL, GetCurrentThreadId()); int r = MessageBox(g_hWnd, tszText, tszCaption, uType); - UnhookWindowsHookEx(hHook); - if (!hHook) throw Win32Error(GetLastError()); + throw_nil<UnhookWindowsHookEx>(hHook); return r; } |