我想求教大家,怎样在程序崩溃的前,把需要的需要的数据保存下来,
或者怎样才能知道,程序要崩溃了………………
一般可以调用SetUnhandledExceptionFilter 捕获dump
LONG WINAPI MyUnhandledExceptionFilter(PEXCEPTION_POINTERS pExcepPointer)
{
MINIDUMP_EXCEPTION_INFORMATION excepInfo = {GetCurrentThreadId(), pExcepPointer, FALSE};
HANDLE hFile = CreateFileW(L"minidump.dmp",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
if (MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &excepInfo, NULL, NULL))
{
printf("Create dump success \n\n");
}
CloseHandle(hFile);
}
printf("ErrorCode:%08X Address:%08X \n\n",
pExcepPointer->ExceptionRecord->ExceptionCode,
pExcepPointer->ExceptionRecord->ExceptionAddress);
return StackTrace(pExcepPointer->ContextRecord);
}