Created
May 18, 2015 09:44
-
-
Save ilebedie/74ceb3fa51d561d32306 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#define UNICODE | |
#include <windows.h> | |
#include <dbghelp.h> | |
#include <shellapi.h> | |
#include <shlobj.h> | |
#include <Strsafe.h> | |
int GenerateDump(EXCEPTION_POINTERS* pExceptionPointers) | |
{ | |
BOOL bMiniDumpSuccessful; | |
WCHAR szPath[MAX_PATH]; | |
WCHAR szFileName[MAX_PATH]; | |
WCHAR* szAppName = L"AppName"; | |
WCHAR* szVersion = L"v1.0"; | |
DWORD dwBufferSize = MAX_PATH; | |
HANDLE hDumpFile; | |
SYSTEMTIME stLocalTime; | |
MINIDUMP_EXCEPTION_INFORMATION ExpParam; | |
GetLocalTime( &stLocalTime ); | |
GetTempPath( dwBufferSize, szPath ); | |
StringCchPrintf( szFileName, MAX_PATH, L"%s%s", szPath, szAppName ); | |
CreateDirectory( szFileName, NULL ); | |
StringCchPrintf( szFileName, MAX_PATH, L"%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", | |
szPath, szAppName, szVersion, | |
stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, | |
stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond, | |
GetCurrentProcessId(), GetCurrentThreadId()); | |
hDumpFile = CreateFile(szFileName, GENERIC_READ|GENERIC_WRITE, | |
FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); | |
ExpParam.ThreadId = GetCurrentThreadId(); | |
ExpParam.ExceptionPointers = pExceptionPointers; | |
ExpParam.ClientPointers = TRUE; | |
bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), | |
hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL); | |
return EXCEPTION_EXECUTE_HANDLER; | |
} | |
void main() | |
{ | |
__try | |
{ | |
int *pBadPtr = NULL; | |
*pBadPtr = 0; | |
} | |
__except(GenerateDump(GetExceptionInformation())) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment