fix macro redefinition when compiling with msvc
[reactos.git] / reactos / subsys / system / taskmgr / debug.c
1 /*
2 * ReactOS Task Manager
3 *
4 * debug.cpp
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <precomp.h>
25
26 void ProcessPage_OnDebug(void)
27 {
28 LVITEM lvitem;
29 ULONG Index;
30 DWORD dwProcessId;
31 TCHAR strErrorText[260];
32 HKEY hKey;
33 TCHAR strDebugPath[260];
34 TCHAR strDebugger[260];
35 DWORD dwDebuggerSize;
36 PROCESS_INFORMATION pi;
37 STARTUPINFO si;
38 HANDLE hDebugEvent;
39 TCHAR szTemp[256];
40 TCHAR szTempA[256];
41
42
43 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
44 {
45 memset(&lvitem, 0, sizeof(LVITEM));
46
47 lvitem.mask = LVIF_STATE;
48 lvitem.stateMask = LVIS_SELECTED;
49 lvitem.iItem = Index;
50
51 ListView_GetItem(hProcessPageListCtrl, &lvitem);
52
53 if (lvitem.state & LVIS_SELECTED)
54 break;
55 }
56
57 dwProcessId = PerfDataGetProcessId(Index);
58
59 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
60 return;
61
62 LoadString(hInst, IDS_MSG_WARNINGDEBUG, szTemp, 256);
63 LoadString(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
64
65 if (MessageBox(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
66 {
67 GetLastErrorText(strErrorText, 260);
68 LoadString(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
69 MessageBox(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
70 return;
71 }
72
73 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
74 {
75 GetLastErrorText(strErrorText, 260);
76 LoadString(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
77 MessageBox(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
78 return;
79 }
80
81 dwDebuggerSize = 260;
82 if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
83 {
84 GetLastErrorText(strErrorText, 260);
85 LoadString(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
86 MessageBox(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
87 RegCloseKey(hKey);
88 return;
89 }
90
91 RegCloseKey(hKey);
92
93 hDebugEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
94 if (!hDebugEvent)
95 {
96 GetLastErrorText(strErrorText, 260);
97 LoadString(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
98 MessageBox(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
99 return;
100 }
101
102 wsprintf(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
103
104 memset(&pi, 0, sizeof(PROCESS_INFORMATION));
105 memset(&si, 0, sizeof(STARTUPINFO));
106 si.cb = sizeof(STARTUPINFO);
107 if (!CreateProcess(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
108 {
109 GetLastErrorText(strErrorText, 260);
110 LoadString(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
111 MessageBox(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
112 }
113
114 CloseHandle(hDebugEvent);
115 }