From 63c6867368c6e605c17ebbea1649b169e72b489c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Tue, 26 Sep 2023 15:30:39 +0200 Subject: [PATCH] Avoid cerr stuttering This also considerably simplifies the code. You may be concerned that I no longer print the reportType. That is because the message already contains it. --- msix/storeapi/dllmain.cpp | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/msix/storeapi/dllmain.cpp b/msix/storeapi/dllmain.cpp index e21996a2b..27d4bea0f 100644 --- a/msix/storeapi/dllmain.cpp +++ b/msix/storeapi/dllmain.cpp @@ -1,36 +1,19 @@ // dllmain.cpp : Defines the entry point for the DLL application. +#include + #include "framework.hpp" #ifdef _MSC_VER #include - -#include -#include - -int DebugReportHook(int reportType, char* message, int* returnValue) { - const auto type = [=]() -> std::string_view { - switch (reportType) { - case _CRT_WARN: - return "[WARNING]"; - case _CRT_ERROR: - return "[ERROR]"; - case _CRT_ASSERT: - return "[ASSERT]"; - default: - return "[UNKNOWN]"; - } - }(); - - std::cerr << type << ' ' << message << std::endl; - throw std::runtime_error(message); -} #else -#define _CrtSetReportHook(x) +constexpr void _CrtSetReportHook(auto) {} #endif // _MSC_VER BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - _CrtSetReportHook(DebugReportHook); + _CrtSetReportHook([](int reportType, char* message, int* returnValue) -> int { + throw std::runtime_error(message); + }); switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: