diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-18 02:03:22 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-18 02:03:22 +0200 |
commit | 34c9abcf6674fece91c6d2750cd424f32cd5d792 (patch) | |
tree | 64b9c8698239033a7556e69e24130195e701d0f8 /c/main.cpp | |
parent | e9044bb1df9e3d6c1c5d8458eb74cbaa5e9faddc (diff) | |
download | EpisodeBrowser-34c9abcf6674fece91c6d2750cd424f32cd5d792.tar.gz |
Ensure that CBT hook is set and unset correctly.
Diffstat (limited to 'c/main.cpp')
-rw-r--r-- | c/main.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -92,10 +92,13 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons if (!RegisterClassEx(&wc)) throw std::runtime_error("Could not register window class."); - /* Create window. Note that a CBT hook is used to initialize - * important global variables before any messages are sent to - * the new window. */ + /* Create window. A CBT hook is used to initialize important + * global variables before any messages are sent to the new + * window. It is vital that the hook is set up and torn down + * correctly. Note that if the unhook fails, it is useless to + * try to show an error dialog. */ const HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); + if (!hHook) throw Win32Error(GetLastError()); const HWND hWnd = CreateWindowEx( 0, TEXT("Episode Browser"), @@ -105,6 +108,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons NULL, NULL, hInstance, NULL ); UnhookWindowsHookEx(hHook); + if (!hHook) _Exit(1); if (!hWnd) throw std::runtime_error("Could not create main window."); g_hWndStatus = CreateStatusBar(hWnd, hInstance); ShowWindow(hWnd, nCmdShow); @@ -142,7 +146,7 @@ void OnTerminate() MessageBoxA(NULL, "The program was terminated due to an exception.", "Fatal Error", MB_ICONERROR); } - std::_Exit(1); + _Exit(1); } static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) |