notepad: Added missing LGPL License in Dutch translations.
[wine] / programs / taskmgr / debug.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  debug.c
5  *
6  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #define WIN32_LEAN_AND_MEAN    /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.h>
32     
33 #include "taskmgr.h"
34 #include "perfdata.h"
35
36 void ProcessPage_OnDebug(void)
37 {
38     LVITEM                lvitem;
39     ULONG                Index;
40     DWORD                dwProcessId;
41     TCHAR                strErrorText[260];
42     HKEY                hKey;
43     TCHAR                strDebugPath[260];
44     TCHAR                strDebugger[260];
45     DWORD                dwDebuggerSize;
46     PROCESS_INFORMATION    pi;
47     STARTUPINFO            si;
48     HANDLE                hDebugEvent;
49
50     for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
51     {
52         lvitem.mask = LVIF_STATE;
53         lvitem.stateMask = LVIS_SELECTED;
54         lvitem.iItem = Index;
55         lvitem.iSubItem = 0;
56
57         SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM) &lvitem);
58
59         if (lvitem.state & LVIS_SELECTED)
60             break;
61     }
62
63     dwProcessId = PerfDataGetProcessId(Index);
64
65     if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
66         return;
67
68     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)
69     {
70         GetLastErrorText(strErrorText, 260);
71         MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
72         return;
73     }
74
75     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
76     {
77         GetLastErrorText(strErrorText, 260);
78         MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
79         return;
80     }
81
82     dwDebuggerSize = 260;
83     if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
84     {
85         GetLastErrorText(strErrorText, 260);
86         MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), 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         MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
98         return;
99     }
100
101     wsprintf(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
102
103     memset(&pi, 0, sizeof(PROCESS_INFORMATION));
104     memset(&si, 0, sizeof(STARTUPINFO));
105     si.cb = sizeof(STARTUPINFO);
106     if (!CreateProcess(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
107     {
108         GetLastErrorText(strErrorText, 260);
109         MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
110     }
111
112     CloseHandle(hDebugEvent);
113 }