dump UnhandledExceptionFilter

版权声明: https://blog.csdn.net/dashoumeixi/article/details/83624826
#include <DbgHelp.h>
#pragma comment(lib, "DbgHelp.lib")
LONG WINAPI MyUnhandledExceptionFilter(
struct _EXCEPTION_POINTERS *ex)
{
	SYSTEMTIME st;
	GetLocalTime(&st);
	TCHAR buf[MAX_PATH];
	DWORD n = GetCurrentDirectory(MAX_PATH, buf);
	buf[n] = 0;
	_stprintf(buf + n, TEXT("%d.%d.%d %d.%d.%d.dump"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

	HANDLE hFile = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE != hFile){
		MINIDUMP_EXCEPTION_INFORMATION miniex;
		miniex.ThreadId = GetCurrentThreadId();
		miniex.ClientPointers = TRUE;
		miniex.ExceptionPointers = ex;
		BOOL ret = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal,
			&miniex, NULL, NULL);
		printf("dump ok \n");
		CloseHandle(hFile);
	}
	else {
		printf("hFile failed\n");
	}
	MessageBox(NULL, TEXT("晕"), TEXT("出错"), MB_OK);

	return EXCEPTION_EXECUTE_HANDLER; 
}
int _tmain(int argc, _TCHAR* argv[])
{
	_tsetlocale(LC_CTYPE, TEXT(""));
	SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
	int *p = 0;
	*p = 1;
	
	
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/dashoumeixi/article/details/83624826