LAPTOP-T815PCOQ\25526
2025-01-10 65ac403060f715a532e5a31927fecbfac208c905
SourceCode/Bond/BoounionPLC/BoounionPLC.cpp
@@ -8,11 +8,60 @@
#include "HorizontalLine.h"
#include "VerticalLine.h"
#include <DbgHelp.h>
#pragma comment(lib, "DbgHelp.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) {
   SYSTEMTIME st;
   GetLocalTime(&st);
   // 获取当前程序运行目录
   char szAppPath[MAX_PATH];
   GetModuleFileName(NULL, szAppPath, MAX_PATH);
   std::string strCurrentDir = szAppPath;
   size_t lastSlash = strCurrentDir.find_last_of("\\/");
   strCurrentDir = strCurrentDir.substr(0, lastSlash);
   // 检查Temp文件夹
   struct stat buffer;
   std::string strFullTempPath = strCurrentDir + "\\Temp";
   if (stat(strFullTempPath.c_str(), &buffer) != 0) {
      if (!CreateDirectory(strFullTempPath.c_str(), NULL)) {
         return EXCEPTION_EXECUTE_HANDLER;
      }
   }
   // 构建文件名
   char szFileName[MAX_PATH];
   snprintf(szFileName, MAX_PATH, "\\BoounionPLC_%04d%02d%02d_%02d%02d%02d.dmp",
      st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
   // 写入DMP文件
   std::string strFullPath = strFullTempPath + szFileName;
   HANDLE hFile = CreateFile(strFullPath.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
   if (hFile != INVALID_HANDLE_VALUE) {
      MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
      dumpInfo.ExceptionPointers = pExceptionInfo;
      dumpInfo.ThreadId = GetCurrentThreadId();
      dumpInfo.ClientPointers = TRUE;
      // 写入dump文件
      BOOL success = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &dumpInfo, NULL, NULL);
      CloseHandle(hFile);
      if (success) {
         CString strMsg;
         strMsg.Format(_T("Software crashes. Dump file: %s"), strFullPath.c_str());
         AfxMessageBox(strMsg);
      }
   }
   return EXCEPTION_EXECUTE_HANDLER;
}
// CBoounionPLCApp
@@ -30,6 +79,7 @@
   // TODO: 在此处添加构造代码,
   // 将所有重要的初始化放置在 InitInstance 中
   SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
}