-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPdbExplorer.h
162 lines (138 loc) · 3.38 KB
/
PdbExplorer.h
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
#pragma once
#include "MainFrm.h"
#include "resource.h"
class CPdbMsgLoop : public CMessageLoop
{
public:
CMainFrame m_wndFrame;
int Run(LPTSTR lpstrCmdLine, int nCmdShow)
{
RECT rc = {0, 0, 1366, 768};
if(m_wndFrame.CreateEx(NULL, rc) == NULL)
{
ATLTRACE(_T("CMainFrame creation failed!\n"));
return 0;
}
if(lpstrCmdLine[0] == 0)
{
}
else // file name specified at the command line
{
// strip quotes (if any)
LPTSTR lpstrCmd = lpstrCmdLine;
if(lpstrCmd[0] == '"')
{
lpstrCmd++;
for(int i = 0; i < lstrlen(lpstrCmd); i++)
{
if(lpstrCmd[i] == '"')
{
lpstrCmd[i] = 0;
break;
}
}
}
// get full path and file name
TCHAR szPathName[MAX_PATH];
LPTSTR lpstrFileName = NULL;
::GetFullPathName(lpstrCmd, MAX_PATH, szPathName, &lpstrFileName);
// open file
m_wndFrame.m_view.LoadFromFile(szPathName);
m_wndFrame.m_mru.AddToList(szPathName);
}
m_wndFrame.CenterWindow();
m_wndFrame.ShowWindow(nCmdShow);
return CMessageLoop::Run();
}
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
return m_wndFrame.PreTranslateMessage(pMsg);
}
virtual BOOL OnIdle(int)
{
m_wndFrame.UpdateUIAll();
return FALSE;
}
};
class CThreadManager
{
public:
// thread init param
struct _RunData
{
LPTSTR lpstrCmdLine;
int nCmdShow;
};
// thread proc
static DWORD WINAPI RunThread(LPVOID lpData)
{
CPdbMsgLoop theLoop;
_Module.AddMessageLoop(&theLoop);
_RunData* pData = (_RunData*)lpData;
int nRet = theLoop.Run(pData->lpstrCmdLine, pData->nCmdShow);
delete pData;
_Module.RemoveMessageLoop();
return nRet;
}
DWORD m_dwCount;
HANDLE m_arrThreadHandles[MAXIMUM_WAIT_OBJECTS - 1];
CThreadManager() : m_dwCount(0)
{ }
// Operations
DWORD AddThread(LPTSTR lpstrCmdLine, int nCmdShow)
{
if(m_dwCount == (MAXIMUM_WAIT_OBJECTS - 1))
{
::MessageBox(NULL, _T("ERROR: Cannot create ANY MORE threads!!!"), _T("PdbExplorer"), MB_OK);
return 0;
}
_RunData* pData = new _RunData;
pData->lpstrCmdLine = lpstrCmdLine;
pData->nCmdShow = nCmdShow;
DWORD dwThreadID;
HANDLE hThread = ::CreateThread(NULL, 0, RunThread, pData, 0, &dwThreadID);
if(hThread == NULL)
{
::MessageBox(NULL, _T("Cannot create thread!!!"), _T("PdbExplorer"), MB_OK);
return 0;
}
m_arrThreadHandles[m_dwCount] = hThread;
m_dwCount++;
return dwThreadID;
}
void RemoveThread(DWORD dwIndex)
{
::CloseHandle(m_arrThreadHandles[dwIndex]);
if(dwIndex != (m_dwCount - 1))
m_arrThreadHandles[dwIndex] = m_arrThreadHandles[m_dwCount - 1];
m_dwCount--;
}
int Run(LPTSTR lpstrCmdLine, int nCmdShow)
{
MSG msg;
// force message queue to be created
::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
AddThread(lpstrCmdLine, nCmdShow);
int nRet = m_dwCount;
DWORD dwRet;
while(m_dwCount > 0)
{
dwRet = ::MsgWaitForMultipleObjects(m_dwCount, m_arrThreadHandles, FALSE, INFINITE, QS_ALLINPUT);
if(dwRet == 0xFFFFFFFF)
::MessageBox(NULL, _T("Wait for multiple objects failed!!!"), _T("PdbExplorer"), MB_OK);
else if(dwRet >= WAIT_OBJECT_0 && dwRet <= (WAIT_OBJECT_0 + m_dwCount - 1))
RemoveThread(dwRet - WAIT_OBJECT_0);
else if(dwRet == (WAIT_OBJECT_0 + m_dwCount))
{
::GetMessage(&msg, NULL, 0, 0);
if(msg.message == WM_USER)
AddThread(_T(""), SW_SHOWNORMAL);
else
::MessageBeep((UINT)-1);
}
else
::MessageBeep((UINT)-1);
}
return nRet;
}
};