Code
#include "stdafx.h"
#include <Windows.h>
#include <DbgHelp.h>
#pragma comment(lib, "DbgHelp.lib")
void CreateMiniDump( LPEXCEPTION_POINTERS lpExceptionInfo) {
// Open a file
HANDLE hFile = CreateFile(_T("MiniDump.dmp"), GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ( hFile != NULL && hFile != INVALID_HANDLE_VALUE ) {
// Create the minidump
MINIDUMP_EXCEPTION_INFORMATION mdei;
mdei.ThreadId = GetCurrentThreadId();
mdei.ExceptionPointers = lpExceptionInfo;
mdei.ClientPointers = FALSE;
MINIDUMP_TYPE mdt = MiniDumpNormal;
BOOL retv = MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
hFile, mdt, ( lpExceptionInfo != 0 ) ? &mdei : 0, 0, 0);
if ( !retv ) {
_tprintf( _T("MiniDumpWriteDump failed. Error: %u \n"), GetLastError() );
} else {
_tprintf( _T("Minidump created.\n") );
}
// Close the file
CloseHandle( hFile );
} else {
_tprintf( _T("CreateFile failed. Error: %u \n"), GetLastError() );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
__try {
int * p = NULL;
*p = 20;
}
__except(CreateMiniDump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) {
}
return 0;
}
在做minidump文件的时候,会有一种情况是写不出dump文件的。那就是在这个异常块的外面还有异常处理模块,并且已经设置了不保存minidump文件处理,这个时候就没办法写出dump来了。
#include "stdafx.h"
#include <Windows.h>
#include <DbgHelp.h>
#pragma comment(lib, "DbgHelp.lib")
void CreateMiniDump( LPEXCEPTION_POINTERS lpExceptionInfo) {
// Open a file
HANDLE hFile = CreateFile(_T("MiniDump.dmp"), GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ( hFile != NULL && hFile != INVALID_HANDLE_VALUE ) {
// Create the minidump
MINIDUMP_EXCEPTION_INFORMATION mdei;
mdei.ThreadId = GetCurrentThreadId();
mdei.ExceptionPointers = lpExceptionInfo;
mdei.ClientPointers = FALSE;
MINIDUMP_TYPE mdt = MiniDumpNormal;
BOOL retv = MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
hFile, mdt, ( lpExceptionInfo != 0 ) ? &mdei : 0, 0, 0);
if ( !retv ) {
_tprintf( _T("MiniDumpWriteDump failed. Error: %u \n"), GetLastError() );
} else {
_tprintf( _T("Minidump created.\n") );
}
// Close the file
CloseHandle( hFile );
} else {
_tprintf( _T("CreateFile failed. Error: %u \n"), GetLastError() );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
__try {
int * p = NULL;
*p = 20;
}
__except(CreateMiniDump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) {
}
return 0;
}
在做minidump文件的时候,会有一种情况是写不出dump文件的。那就是在这个异常块的外面还有异常处理模块,并且已经设置了不保存minidump文件处理,这个时候就没办法写出dump来了。