From f9228256ae6f52f7fcc7717a53780586bed10e15 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 11 Oct 2016 14:29:25 +0300 Subject: hardening --- src/error.hpp | 3 ++- src/main.cpp | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/error.hpp b/src/error.hpp index e8f47a4..0c5b917 100644 --- a/src/error.hpp +++ b/src/error.hpp @@ -7,6 +7,7 @@ #include +#include #include typedef std::system_error Error; @@ -24,7 +25,7 @@ namespace error throw make(function_name); } - void report(const Error& e) + void report(const std::exception& e) { MessageBoxA(NULL, e.what(), NULL, MB_OK); } diff --git a/src/main.cpp b/src/main.cpp index be8d5e7..3ae2bcc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") @@ -223,17 +224,25 @@ int APIENTRY wWinMain( wchar_t*, int) { - const auto ret = DialogBoxW( - instance, - MAKEINTRESOURCE(IDD_MAINDIALOG), - NULL, - dialog_main); + try + { + const auto ret = DialogBoxW( + instance, + MAKEINTRESOURCE(IDD_MAINDIALOG), + NULL, + dialog_main); - switch (ret) + switch (ret) + { + case -1: + error::report(error::make("DialogBoxW")); + default: + return static_cast(ret); + } + } + catch (const std::exception& e) { - case -1: - error::report(error::make("DialogBoxW")); - default: - return static_cast(ret); + error::report(e); + return 1; } } -- cgit v1.2.3