aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/main.cpp')
-rw-r--r--c/main.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/c/main.cpp b/c/main.cpp
index 885d045..6a172e5 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -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)