程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> C++軟件添加dump調試打印日志

C++軟件添加dump調試打印日志

編輯:關於C++
#include

#pragma comment(lib, "dbghelp.lib")

LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)
{
//cout << "Enter TopLevelExceptionFilter Function" << endl;
  TCHAR szPath[MAX_PATH] = { 0 };
  TCHAR szFileName[MAX_PATH] = { 0 };
  TCHAR* szVersion = "v1.0";
  TCHAR dwBufferSize = MAX_PATH;
  SYSTEMTIME stLocalTime;
  GetLocalTime(&stLocalTime);
  CreateDirectory(szFileName, NULL);
  StringCchPrintf(szFileName, MAX_PATH, "%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp",
  szVersion, stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay,
  stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond,
  GetCurrentProcessId(), GetCurrentThreadId());

  HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 MINIDUMP_EXCEPTION_INFORMATION stExceptionParam;
stExceptionParam.ThreadId = GetCurrentThreadId();
stExceptionParam.ExceptionPointers = pExceptionInfo;
stExceptionParam.ClientPointers = FALSE;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &stExceptionParam, NULL, NULL);
CloseHandle(hFile);
getchar();

return EXCEPTION_EXECUTE_HANDLER;
}

//-----------------------------------------------------------------------------------------

在程序最開始的地方調用這個函數

SetUnhandledExceptionFilter(TopLevelExceptionFilter);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved