mrDarker
2025-07-14 1c0ac1c7924efb8a2cb6962d3eda4126533a5ac8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
 
// ENRIT.cpp : 定义应用程序的类动作。
//
 
#include "stdafx.h"
#include "afxwinappex.h"
#include "afxdialogex.h"
#include "ENRIT.h"
#include "MainFrm.h"
 
#include "ENRITDoc.h"
#include "ENRITView.h"
 
#include <gdiplus.h>
using namespace Gdiplus;
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
#pragma comment(lib, "DbgHelp.lib")
 
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) {
    //RCutProject_DmpFile.dmp
    
    char szFileName[MAX_PATH];
    struct stat buffer;
    if (stat("D:\\Temp", &buffer) != 0)
    {
        CreateDirectory(_T("D:\\Temp"), NULL);
    }
 
    if (stat("D:\\Temp\\Log", &buffer) != 0)
    {
        CreateDirectory(_T("D:\\Temp\\Log"), NULL);
    }
 
    CString file_path;
    file_path.Format(_T("D:\\Temp\\Log\\%s.csv"), g_pBase->m_strLoadingDay);
 
    CFile file_module;
    CFileException exception;
 
    file_module.Open(file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &exception);
 
    if (exception.m_cause == CFileException::none)
    {
        if (file_module.SeekToEnd() == 0L)
        {
            CString defect_title;
            defect_title.Format(_T("Date,GlassID,Path,Versions\r\n"));
            file_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR));
        }
 
        SYSTEMTIME st;
        GetLocalTime(&st);
 
        CString strTime;
        strTime.Format(_T("%02d:%02d:%02d"), st.wHour, st.wMinute, st.wSecond);
        CString strVersions = L"";
 
        TCHAR szAppFile[MAX_PATH] = { 0 };
        ::GetModuleFileName(NULL, szAppFile, MAX_PATH);
 
        HANDLE hAppFile = CreateFile(szAppFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
        if (hAppFile != INVALID_HANDLE_VALUE)
        {
            FILETIME fileTime_Create;
            FILETIME fileTime_LastAccess;
            FILETIME fileTime_LastWrite;
 
            if (!GetFileTime(hAppFile, &fileTime_Create, &fileTime_LastAccess, &fileTime_LastWrite))
            {
                CloseHandle(hAppFile);
            }
            else
            {
                FILETIME fileTime_Local;
                FileTimeToLocalFileTime(&fileTime_LastWrite, &fileTime_Local);
                FileTimeToSystemTime(&fileTime_Local, &st);
 
                strVersions.Format(L"%04d/%02d/%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
 
                CloseHandle(hAppFile);
            }
        }
 
        CString strData;
        strData.Format(_T("%s,%s,%s,%s\r\n"), strTime, g_pBase->m_strHPanelID, szAppFile, strVersions);
        file_module.Write(strData, strData.GetLength() * sizeof(TCHAR));
        file_module.Close();
    }
 
    snprintf(szFileName, MAX_PATH, "D:\\Temp\\RCutProject_DmpFile.dmp");
 
    AfxMessageBox(_T("system failure!!!"));
 
    // ?孙冼遂
    HANDLE hFile = CreateFileA(szFileName, 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, MiniDumpFilterMemory, &dumpInfo, NULL, NULL);
        CloseHandle(hFile);
 
        if (!success) {
            std::cerr << "Failed to write dump file." << std::endl;
        }
        else {
            std::cerr << "Dump file written to " << szFileName << std::endl;
        }
    }
    else {
        std::cerr << "Failed to create dump file." << std::endl;
    }
 
    return EXCEPTION_EXECUTE_HANDLER;
}
 
// CENRITApp
 
BEGIN_MESSAGE_MAP(CENRITApp, CWinApp)
    ON_COMMAND(ID_APP_ABOUT, &CENRITApp::OnAppAbout)
    // 基于标准文件的文件命令。
    ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
    ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
END_MESSAGE_MAP()
 
 
// CENRITApp 生成
 
CENRITApp::CENRITApp()
{
    // TODO: 将下面的应用程序ID字符串替换为固有ID字符串(建议)。
    // 字符串的格式: CompanyName.ProductName.SubProduct.VersionInformation
    SetAppID(_T("ENRIT.AppID.NoVersion"));
 
    m_bCreateBase = FALSE;
    m_bCreateLog = FALSE;
    m_hMutex = NULL;
}
 
// 唯一的CENRITApp个体。
 
CENRITApp theApp;
 
 
// CENRITApp 初始化
 
BOOL CENRITApp::InitInstance()
{
    SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
    CWinApp::InitInstance();
 
    m_hMutex = ::CreateMutex(NULL,FALSE, _T("MutexRCutInspector"));
    if (m_hMutex != NULL)
    {
        if(::GetLastError() == ERROR_ALREADY_EXISTS) 
        {    
            AfxMessageBox(_T("The Program is already running. Exit this Program."), MB_OK | MB_ICONERROR);
            return FALSE;
        }
    }    
 
    if (!AfxSocketInit())
    {
        AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
        return FALSE;
    }
 
    // 初始化OLE库。
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
 
    AfxEnableControlContainer();
 
    EnableTaskbarInteraction(FALSE);
 
    // 要使用RichEdit控制,必须有AfxInitRichEdit2()。
    // AfxInitRichEdit2();
 
    // 标准初始化
    // 如果想在不使用这些功能的情况下缩小最终可执行文件的大小
    // 下面不需要的特定初始化
    // 你必须去除例行动作。
    // 更改保存该设置的注册表键。
    // TODO: 将该字符串与公司名称或组织名称相同
    // 应该修改成适当的内容。
    SetRegistryKey(_T("本地应用程序向导中生成的应用程序"));
    LoadStdProfileSettings(4);  // 加载标准INI文件选项,包括MRU。
 
    if (NULL != g_pBase)
    {
        m_bCreateBase = TRUE;
    }
 
    if (NULL != g_pLog)
    {
        m_bCreateLog = TRUE;
        //g_pLog->SetPath(_T("C:\\RCutProject\\log"));
    }
 
    if (NULL != g_pLang)
    {
        m_bCreateLang = TRUE;
    }
 
    // 注册应用程序的文档模板。
    // 文档模板是文档、框架窗口和视图之间的连接。
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
        IDR_MAINFRAME,
        RUNTIME_CLASS(CENRITDoc),
        RUNTIME_CLASS(CMainFrame),       // 主要SDI框架窗口。
        RUNTIME_CLASS(CENRITView));
    if (!pDocTemplate)
        return FALSE;
    AddDocTemplate(pDocTemplate);
 
    // 分析标准外壳命令、DDE和打开文件的命令行。
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
 
    // 在命令行中删除指定的命令。
    // 如果应用程序以/RegServer、/Register、/Unregserver或/Unregister启动,则返回FALSE。
    if (!ProcessShellCommand(cmdInfo))
        return FALSE;
 
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
 
    // 只有一个窗口初始化,显示并更新。
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    // 只有在有后缀时才调用DragAcceptFiles。
    // 在SDI的应用程序中,ProcessShellCommand之后应该发生这样的调用。
 
    CMainFrame* pMain = static_cast<CMainFrame*>(AfxGetMainWnd());
    //pMain->SetDoc(static_cast<CAlignInspectionDoc*>(pMain->GetActiveDocument()));
    pMain->SetView(static_cast<CENRITView*>(pMain->GetActiveView()));
 
    m_bCreateLog = TRUE;
 
    return TRUE;
}
 
int CENRITApp::ExitInstance()
{
    m_bCreateBase = FALSE;
    m_bCreateLog = FALSE; 
    m_bCreateLang = FALSE;
 
    CloseHandle(m_hMutex);
 
    //TODO: 处理添加的资源。
    AfxOleTerm(FALSE);
 
    return CWinApp::ExitInstance();
}
 
// CENRITApp消息处理器
 
 
// 用于应用程序信息的CAboutDlg对话框。
 
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();
 
    // 对话框数据。
    enum { IDD = IDD_ABOUTBOX };
 
protected:
    virtual void DoDataExchange(CDataExchange* pDX);
 
    // 实现。
protected:
    DECLARE_MESSAGE_MAP()
};
 
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
 
// 用于运行对话框的应用程序命令。
void CENRITApp::OnAppAbout()
{
    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
}
 
// CENRITApp消息处理器