Created
October 26, 2020 18:39
-
-
Save Donpedro13/0dbef622e1cf3579e398f5a6043c9915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <werapi.h> | |
extern "C" { | |
__declspec(dllexport) HRESULT WINAPI OutOfProcessExceptionEventCallback ( | |
PVOID /*pContext*/, | |
const PWER_RUNTIME_EXCEPTION_INFORMATION /*pExceptionInformation*/, | |
BOOL* pbOwnershipClaimed, | |
PWSTR pwszEventName, | |
PDWORD pchSize, | |
PDWORD pdwSignatureCount) | |
{ | |
*pbOwnershipClaimed = TRUE; // Claim this crash | |
const WCHAR* eventDescription = L"Your event description"; | |
wcscpy (pwszEventName, eventDescription); | |
// According to the documentation, we must include the terminating L'\0' | |
*pchSize = wcslen (eventDescription) + 1; | |
// Call back OutOfProcessExceptionEventSignatureCallback exactly one time | |
*pdwSignatureCount = 1; | |
return S_OK; | |
} | |
__declspec(dllexport) HRESULT WINAPI OutOfProcessExceptionEventSignatureCallback ( | |
PVOID /*pContext*/, | |
const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation, | |
DWORD /*dwIndex*/, | |
PWSTR /*pwszName*/, | |
PDWORD /*pchName*/, | |
PWSTR /*pwszValue*/, | |
PDWORD /*pchValue*/) | |
{ | |
// pExceptionInformation contains an exception record, HANDLEs to the | |
// crashing thread and process, and the crashing thread's context. | |
// Using these you can write a minidump, walk the stack, etc. | |
// [ Handle the crash here using pExceptionInformation ] | |
// Terminate WER's workflow by terminating the crashing process | |
TerminateProcess (pExceptionInformation->hProcess, | |
pExceptionInformation->exceptionRecord.ExceptionCode); | |
// From the viewpoint of WER this function did not succeed, because | |
// we did not provide the parameter name and value (pchName, pchValue) | |
return E_FAIL; | |
} | |
__declspec(dllexport) HRESULT WINAPI OutOfProcessExceptionEventDebuggerLaunchCallback( | |
PVOID /*pContext*/, | |
const PWER_RUNTIME_EXCEPTION_INFORMATION /*pExceptionInformation*/, | |
PBOOL /*pbIsCustomDebugger*/, | |
PWSTR /*pwszDebuggerLaunch*/, | |
PDWORD /*pchDebuggerLaunch*/, | |
PBOOL /*pbIsDebuggerAutolaunch*/) | |
{ | |
// Since we returned E_FAIL in OutOfProcessExceptionEventSignatureCallback, | |
// this should not be called by WER | |
return E_FAIL; | |
} | |
} // extern "C" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment