void CreateMiniDump(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
HMODULE hModule = ::LoadLibrary(".\\dbghelp.dll");
if( NULL == hModule )
return;
MiniDumpWriteDump_PTR pfnMiniDumpWriteDump = (MiniDumpWriteDump_PTR)GetProcAddress(hModule, "MiniDumpWriteDump");
if( NULL == pfnMiniDumpWriteDump )
{
FreeLibrary(hModule);
return;
}
char szFile[MAX_PATH+1] = {0};
_snprintf(szFile, MAX_PATH, ".\\cc_%u.dmp", time(NULL));
HANDLE hFile = CreateFile(szFile, GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if( INVALID_HANDLE_VALUE == hFile )
{
FreeLibrary(hModule);
return;
}
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ClientPointers = TRUE;
mei.ExceptionPointers = ExceptionInfo;
// (*pfnMiniDumpWriteDump)(GetCurrentProcess(), GetCurrentProcessId(), hFile,
// MiniDumpWithFullMemory,
// &mei, NULL, NULL);
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
MiniDumpWithFullMemory,
&mei, NULL, NULL);
CloseHandle(hFile);
FreeLibrary(hModule);
}
struct _EXCEPTION_POINTERS gEx;
DWORD FilterFunction(struct _EXCEPTION_POINTERS* ex)
{
memcpy(&gEx,ex,sizeof(_EXCEPTION_POINTERS));
return 1;
}
void Dmp()
{
__try
{
// try block
throw 12;
}
__except ( FilterFunction(GetExceptionInformation()) )
{
// exception handler block
CreateMiniDump(&gEx);
}
}