6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
36 void ProcessPage_OnDebug(void)
41 TCHAR strErrorText[260];
43 TCHAR strDebugPath[260];
44 TCHAR strDebugger[260];
46 PROCESS_INFORMATION pi;
50 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
52 memset(&lvitem, 0, sizeof(LVITEM));
54 lvitem.mask = LVIF_STATE;
55 lvitem.stateMask = LVIS_SELECTED;
58 SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM) &lvitem);
60 if (lvitem.state & LVIS_SELECTED)
64 dwProcessId = PerfDataGetProcessId(Index);
66 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
69 if (MessageBox(hMainWnd, _T("WARNING: Debugging this process may result in loss of data.\nAre you sure you wish to attach the debugger?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
71 GetLastErrorText(strErrorText, 260);
72 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
76 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
78 GetLastErrorText(strErrorText, 260);
79 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
84 if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
86 GetLastErrorText(strErrorText, 260);
87 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
94 hDebugEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
97 GetLastErrorText(strErrorText, 260);
98 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
102 wsprintf(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
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))
109 GetLastErrorText(strErrorText, 260);
110 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
113 CloseHandle(hDebugEvent);