Skip to content

Instantly share code, notes, and snippets.

@alpinskiy
Created July 18, 2019 07:19
Show Gist options
  • Save alpinskiy/85366616730b77216c68eb78796f2207 to your computer and use it in GitHub Desktop.
Save alpinskiy/85366616730b77216c68eb78796f2207 to your computer and use it in GitHub Desktop.
#include <Windows.h>
#include <cstdio>
LONG WINAPI ExceptionHandlerProc(_EXCEPTION_POINTERS *exceptionInfo) {
printf("Exception code %d", exceptionInfo->ExceptionRecord->ExceptionCode);
return EXCEPTION_CONTINUE_SEARCH;
}
PVOID ExceptionHandler;
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason,
IN LPVOID Reserved) {
BOOLEAN bSuccess = TRUE;
switch (nReason) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hDllHandle);
ExceptionHandler = AddVectoredExceptionHandler(1, ExceptionHandlerProc);
if (ExceptionHandler) printf("Registred exception handler");
break;
case DLL_PROCESS_DETACH:
if (ExceptionHandler) {
RemoveVectoredExceptionHandler(ExceptionHandler);
if (ExceptionHandler) printf("Unregistred exception handler");
}
break;
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment