Removed direct access to the WND struct.
[wine/dcerpc.git] / misc / toolhelp.c
blob8541336ac1a502b3086cacf0a3600b151b8a7cc3
1 /*
2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include <assert.h>
12 #include "winbase.h"
13 #include "wine/winbase16.h"
14 #include "winerror.h"
15 #include "process.h"
16 #include "tlhelp32.h"
17 #include "toolhelp.h"
18 #include "heap.h"
19 #include "server.h"
20 #include "debug.h"
23 /* FIXME: to make this working, we have to callback all these registered
24 * functions from all over the WINE code. Someone with more knowledge than
25 * me please do that. -Marcus
27 static struct notify
29 HTASK16 htask;
30 FARPROC16 lpfnCallback;
31 WORD wFlags;
32 } *notifys = NULL;
34 static int nrofnotifys = 0;
36 static FARPROC16 HookNotify = NULL;
38 BOOL16 WINAPI NotifyRegister16( HTASK16 htask, FARPROC16 lpfnCallback,
39 WORD wFlags )
41 int i;
43 TRACE(toolhelp, "(%x,%lx,%x) called.\n",
44 htask, (DWORD)lpfnCallback, wFlags );
45 if (!htask) htask = GetCurrentTask();
46 for (i=0;i<nrofnotifys;i++)
47 if (notifys[i].htask==htask)
48 break;
49 if (i==nrofnotifys) {
50 if (notifys==NULL)
51 notifys=(struct notify*)HeapAlloc( SystemHeap, 0,
52 sizeof(struct notify) );
53 else
54 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
55 sizeof(struct notify)*(nrofnotifys+1));
56 if (!notifys) return FALSE;
57 nrofnotifys++;
59 notifys[i].htask=htask;
60 notifys[i].lpfnCallback=lpfnCallback;
61 notifys[i].wFlags=wFlags;
62 return TRUE;
65 BOOL16 WINAPI NotifyUnregister16( HTASK16 htask )
67 int i;
69 TRACE(toolhelp, "(%x) called.\n", htask );
70 if (!htask) htask = GetCurrentTask();
71 for (i=nrofnotifys;i--;)
72 if (notifys[i].htask==htask)
73 break;
74 if (i==-1)
75 return FALSE;
76 memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
77 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
78 (nrofnotifys-1)*sizeof(struct notify));
79 nrofnotifys--;
80 return TRUE;
83 BOOL16 WINAPI StackTraceCSIPFirst16(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
85 return TRUE;
88 BOOL16 WINAPI StackTraceFirst16(STACKTRACEENTRY *ste, HTASK16 Task)
90 return TRUE;
93 BOOL16 WINAPI StackTraceNext16(STACKTRACEENTRY *ste)
95 return TRUE;
98 /***********************************************************************
99 * ToolHelpHook (KERNEL.341)
100 * see "Undocumented Windows"
102 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
104 FARPROC16 tmp;
105 tmp = HookNotify;
106 HookNotify = lpfnNotifyHandler;
107 /* just return previously installed notification function */
108 return tmp;
112 /***********************************************************************
113 * CreateToolHelp32Snapshot (KERNEL32.179)
115 HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
117 struct create_snapshot_request req;
118 struct create_snapshot_reply reply;
120 TRACE( toolhelp, "%lx,%lx\n", flags, process );
121 if (flags & (TH32CS_SNAPHEAPLIST|TH32CS_SNAPMODULE|TH32CS_SNAPTHREAD))
122 FIXME( toolhelp, "flags %lx not implemented\n", flags );
123 if (!(flags & TH32CS_SNAPPROCESS))
125 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
126 return INVALID_HANDLE_VALUE;
129 /* Now do the snapshot */
130 req.flags = flags & ~TH32CS_INHERIT;
131 req.inherit = (flags & TH32CS_INHERIT) != 0;
132 CLIENT_SendRequest( REQ_CREATE_SNAPSHOT, -1, 1, &req, sizeof(req) );
133 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
134 return reply.handle;
138 /***********************************************************************
139 * TOOLHELP_Process32Next
141 * Implementation of Process32First/Next
143 static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL first )
145 struct next_process_request req;
146 struct next_process_reply reply;
148 if (lppe->dwSize < sizeof (PROCESSENTRY))
150 SetLastError( ERROR_INSUFFICIENT_BUFFER );
151 ERR (toolhelp, "Result buffer too small\n");
152 return FALSE;
154 req.handle = handle;
155 req.reset = first;
156 CLIENT_SendRequest( REQ_NEXT_PROCESS, -1, 1, &req, sizeof(req) );
157 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
158 lppe->cntUsage = 1;
159 lppe->th32ProcessID = (DWORD)reply.pid;
160 lppe->th32DefaultHeapID = 0; /* FIXME */
161 lppe->th32ModuleID = 0; /* FIXME */
162 lppe->cntThreads = reply.threads;
163 lppe->th32ParentProcessID = 0; /* FIXME */
164 lppe->pcPriClassBase = reply.priority;
165 lppe->dwFlags = -1; /* FIXME */
166 lppe->szExeFile[0] = 0; /* FIXME */
167 return TRUE;
171 /***********************************************************************
172 * Process32First (KERNEL32.555)
174 * Return info about the first process in a toolhelp32 snapshot
176 BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY lppe)
178 return TOOLHELP_Process32Next( hSnapshot, lppe, TRUE );
181 /***********************************************************************
182 * Process32Next (KERNEL32.556)
184 * Return info about the "next" process in a toolhelp32 snapshot
186 BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY lppe)
188 return TOOLHELP_Process32Next( hSnapshot, lppe, FALSE );