Merge from amd64-branch:
[reactos.git] / reactos / base / applications / 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <precomp.h>
25
26 void ProcessPage_OnDebug(void)
27 {
28 DWORD dwProcessId;
29 WCHAR strErrorText[260];
30 HKEY hKey;
31 WCHAR strDebugPath[260];
32 WCHAR strDebugger[260];
33 DWORD dwDebuggerSize;
34 PROCESS_INFORMATION pi;
35 STARTUPINFOW si;
36 HANDLE hDebugEvent;
37 WCHAR szTemp[256];
38 WCHAR szTempA[256];
39
40 dwProcessId = GetSelectedProcessId();
41
42 if (dwProcessId == 0)
43 return;
44
45 LoadStringW(hInst, IDS_MSG_WARNINGDEBUG, szTemp, 256);
46 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
47
48 if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
49 {
50 GetLastErrorText(strErrorText, 260);
51 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
52 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
53 return;
54 }
55
56 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
57 {
58 GetLastErrorText(strErrorText, 260);
59 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
60 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
61 return;
62 }
63
64 dwDebuggerSize = 260;
65 if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
66 {
67 GetLastErrorText(strErrorText, 260);
68 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
69 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
70 RegCloseKey(hKey);
71 return;
72 }
73
74 RegCloseKey(hKey);
75
76 hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
77 if (!hDebugEvent)
78 {
79 GetLastErrorText(strErrorText, 260);
80 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
81 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
82 return;
83 }
84
85 wsprintfW(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
86
87 memset(&pi, 0, sizeof(PROCESS_INFORMATION));
88 memset(&si, 0, sizeof(STARTUPINFOW));
89 si.cb = sizeof(STARTUPINFOW);
90 if (!CreateProcessW(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
91 {
92 GetLastErrorText(strErrorText, 260);
93 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
94 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
95 }
96
97 CloseHandle(hDebugEvent);
98 }