Skip to content

Commit

Permalink
Install report hook in StoreAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Sep 26, 2023
1 parent eda4994 commit 6f28e2a
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions msix/storeapi/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "framework.hpp"

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
#ifdef _MSC_VER
#include <Windows.h>

#include <iostream>
#include <string_view>

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)
#endif // _MSC_VER

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved) {
_CrtSetReportHook(DebugReportHook);

switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
break;
}
return TRUE;
}

0 comments on commit 6f28e2a

Please sign in to comment.