Added function table to GDI objects for better encapsulation.
[wine.git] / dlls / psapi / psapi_main.c
blob211defde9281839f692eb58bfa7951d641d96d2f
1 /*
2 * PSAPI library
4 * Copyright 1998 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "winbase.h"
22 #include "windef.h"
23 #include "winerror.h"
24 #include "wine/server.h"
25 #include "wine/debug.h"
26 #include "tlhelp32.h"
27 #include "psapi.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(psapi);
31 #include <string.h>
34 /***********************************************************************
35 * get pid from hProcess (internal)
37 static DWORD get_pid_from_process_handle(HANDLE hProcess)
39 DWORD ret = 0;
41 SERVER_START_REQ( get_process_info )
43 req->handle = hProcess;
44 if ( !wine_server_call_err( req ) )
45 ret = (DWORD)reply->pid;
47 SERVER_END_REQ;
49 return ret;
52 /***********************************************************************
53 * EmptyWorkingSet (PSAPI.@)
55 BOOL WINAPI EmptyWorkingSet(HANDLE hProcess)
57 return SetProcessWorkingSetSize(hProcess, 0xFFFFFFFF, 0xFFFFFFFF);
60 /***********************************************************************
61 * EnumDeviceDrivers (PSAPI.@)
63 BOOL WINAPI EnumDeviceDrivers(
64 LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded)
66 FIXME("(%p, %ld, %p): stub\n", lpImageBase, cb, lpcbNeeded);
68 if(lpcbNeeded)
69 *lpcbNeeded = 0;
71 return TRUE;
75 /***********************************************************************
76 * EnumProcesses (PSAPI.@)
78 BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, DWORD *lpcbNeeded)
80 PROCESSENTRY32 pe;
81 HANDLE hSnapshot;
82 BOOL res;
83 DWORD count;
84 DWORD countMax;
86 FIXME("(%p, %ld, %p)\n", lpidProcess,cb, lpcbNeeded);
88 if ( lpidProcess == NULL )
89 cb = 0;
90 if ( lpcbNeeded != NULL )
91 *lpcbNeeded = 0;
93 hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
94 if ( hSnapshot == INVALID_HANDLE_VALUE )
96 FIXME("cannot create snapshot\n");
97 return FALSE;
99 count = 0;
100 countMax = cb / sizeof(DWORD);
101 while (1)
103 ZeroMemory( &pe, sizeof(PROCESSENTRY32) );
104 pe.dwSize = sizeof(PROCESSENTRY32);
105 res = (count == 0) ? Process32First( hSnapshot, &pe ) : Process32Next( hSnapshot, &pe );
106 if ( !res )
107 break;
108 TRACE("process 0x%08lx\n",(long)pe.th32ProcessID);
109 if ( count < countMax )
110 lpidProcess[count] = pe.th32ProcessID;
111 count ++;
113 CloseHandle( hSnapshot );
115 if ( lpcbNeeded != NULL )
116 *lpcbNeeded = sizeof(DWORD) * count;
118 TRACE("return %lu processes\n",count);
120 return TRUE;
123 /***********************************************************************
124 * EnumProcessModules (PSAPI.@)
126 BOOL WINAPI EnumProcessModules(
127 HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
129 MODULEENTRY32 me;
130 HANDLE hSnapshot;
131 BOOL res;
132 DWORD pid;
133 DWORD count;
134 DWORD countMax;
136 FIXME("(hProcess=0x%08x, %p, %ld, %p)\n",
137 hProcess, lphModule, cb, lpcbNeeded );
139 if ( lphModule == NULL )
140 cb = 0;
141 if ( lpcbNeeded != NULL )
142 *lpcbNeeded = 0;
144 pid = get_pid_from_process_handle(hProcess);
145 if ( pid == 0 )
147 FIXME("no pid for hProcess 0x%08x\n",hProcess);
148 return FALSE;
151 hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid);
152 if ( hSnapshot == INVALID_HANDLE_VALUE )
154 FIXME("cannot create snapshot\n");
155 return FALSE;
157 count = 0;
158 countMax = cb / sizeof(HMODULE);
159 while (1)
161 ZeroMemory( &me, sizeof(MODULEENTRY32) );
162 me.dwSize = sizeof(MODULEENTRY32);
163 res = (count == 0) ? Module32First( hSnapshot, &me ) : Module32Next( hSnapshot, &me );
164 if ( !res )
165 break;
166 TRACE("module 0x%08lx\n",(long)me.hModule);
167 if ( count < countMax )
168 lphModule[count] = me.hModule;
169 count ++;
171 CloseHandle( hSnapshot );
173 if ( lpcbNeeded != NULL )
174 *lpcbNeeded = sizeof(HMODULE) * count;
176 TRACE("return %lu modules\n",count);
178 return TRUE;
181 /***********************************************************************
182 * GetDeviceDriverBaseNameA (PSAPI.@)
184 DWORD WINAPI GetDeviceDriverBaseNameA(
185 LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
187 FIXME("(%p, %s, %ld): stub\n",
188 ImageBase, debugstr_a(lpBaseName), nSize
191 if(lpBaseName && nSize)
192 lpBaseName[0] = '\0';
194 return 0;
197 /***********************************************************************
198 * GetDeviceDriverBaseNameW (PSAPI.@)
200 DWORD WINAPI GetDeviceDriverBaseNameW(
201 LPVOID ImageBase, LPWSTR lpBaseName, DWORD nSize)
203 FIXME("(%p, %s, %ld): stub\n",
204 ImageBase, debugstr_w(lpBaseName), nSize
207 if(lpBaseName && nSize)
208 lpBaseName[0] = '\0';
210 return 0;
213 /***********************************************************************
214 * GetDeviceDriverFileNameA (PSAPI.@)
216 DWORD WINAPI GetDeviceDriverFileNameA(
217 LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
219 FIXME("(%p, %s, %ld): stub\n",
220 ImageBase, debugstr_a(lpFilename), nSize
223 if(lpFilename && nSize)
224 lpFilename[0] = '\0';
226 return 0;
229 /***********************************************************************
230 * GetDeviceDriverFileNameW (PSAPI.@)
232 DWORD WINAPI GetDeviceDriverFileNameW(
233 LPVOID ImageBase, LPWSTR lpFilename, DWORD nSize)
235 FIXME("(%p, %s, %ld): stub\n",
236 ImageBase, debugstr_w(lpFilename), nSize
239 if(lpFilename && nSize)
240 lpFilename[0] = '\0';
242 return 0;
245 /***********************************************************************
246 * GetMappedFileNameA (PSAPI.@)
248 DWORD WINAPI GetMappedFileNameA(
249 HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize)
251 FIXME("(hProcess=0x%08x, %p, %s, %ld): stub\n",
252 hProcess, lpv, debugstr_a(lpFilename), nSize
255 if(lpFilename && nSize)
256 lpFilename[0] = '\0';
258 return 0;
261 /***********************************************************************
262 * GetMappedFileNameW (PSAPI.@)
264 DWORD WINAPI GetMappedFileNameW(
265 HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize)
267 FIXME("(hProcess=0x%08x, %p, %s, %ld): stub\n",
268 hProcess, lpv, debugstr_w(lpFilename), nSize
271 if(lpFilename && nSize)
272 lpFilename[0] = '\0';
274 return 0;
277 /***********************************************************************
278 * GetModuleBaseNameA (PSAPI.@)
280 DWORD WINAPI GetModuleBaseNameA(
281 HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize)
283 FIXME("(hProcess=0x%08x, hModule=0x%08x, %s, %ld): stub\n",
284 hProcess, hModule, debugstr_a(lpBaseName), nSize
287 if(lpBaseName && nSize)
288 lpBaseName[0] = '\0';
290 return 0;
293 /***********************************************************************
294 * GetModuleBaseNameW (PSAPI.@)
296 DWORD WINAPI GetModuleBaseNameW(
297 HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
299 FIXME("(hProcess=0x%08x, hModule=0x%08x, %s, %ld): stub\n",
300 hProcess, hModule, debugstr_w(lpBaseName), nSize);
302 if(lpBaseName && nSize)
303 lpBaseName[0] = '\0';
305 return 0;
308 /***********************************************************************
309 * GetModuleFileNameExA (PSAPI.@)
311 DWORD WINAPI GetModuleFileNameExA(
312 HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize)
314 FIXME("(hProcess=0x%08x,hModule=0x%08x, %s, %ld): stub\n",
315 hProcess, hModule, debugstr_a(lpFilename), nSize
318 if ( get_pid_from_process_handle(hProcess) == GetCurrentProcessId() )
319 return GetModuleFileNameA( hModule, lpFilename, nSize );
321 if(lpFilename&&nSize)
322 lpFilename[0]='\0';
324 return 0;
327 /***********************************************************************
328 * GetModuleFileNameExW (PSAPI.@)
330 DWORD WINAPI GetModuleFileNameExW(
331 HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
333 FIXME("(hProcess=0x%08x,hModule=0x%08x, %s, %ld): stub\n",
334 hProcess, hModule, debugstr_w(lpFilename), nSize
337 if ( get_pid_from_process_handle(hProcess) == GetCurrentProcessId() )
338 return GetModuleFileNameW( hModule, lpFilename, nSize );
340 if(lpFilename && nSize)
341 lpFilename[0] = '\0';
343 return 0;
346 /***********************************************************************
347 * GetModuleInformation (PSAPI.@)
349 BOOL WINAPI GetModuleInformation(
350 HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb)
352 FIXME("(hProcess=0x%08x, hModule=0x%08x, %p, %ld): stub\n",
353 hProcess, hModule, lpmodinfo, cb
356 memset(lpmodinfo, 0, cb);
358 return TRUE;
361 /***********************************************************************
362 * GetProcessMemoryInfo (PSAPI.@)
364 BOOL WINAPI GetProcessMemoryInfo(
365 HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
367 FIXME("(hProcess=0x%08x, %p, %ld): stub\n",
368 Process, ppsmemCounters, cb
371 memset(ppsmemCounters, 0, cb);
373 return TRUE;
376 /***********************************************************************
377 * GetWsChanges (PSAPI.@)
379 BOOL WINAPI GetWsChanges(
380 HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb)
382 FIXME("(hProcess=0x%08x, %p, %ld): stub\n",
383 hProcess, lpWatchInfo, cb
386 memset(lpWatchInfo, 0, cb);
388 return TRUE;
391 /***********************************************************************
392 * InitializeProcessForWsWatch (PSAPI.@)
394 BOOL WINAPI InitializeProcessForWsWatch(HANDLE hProcess)
396 FIXME("(hProcess=0x%08x): stub\n", hProcess);
398 return TRUE;
401 /***********************************************************************
402 * QueryWorkingSet (PSAPI.?)
403 * FIXME
404 * I haven't been able to find the ordinal for this function,
405 * This means it can't be called from outside the DLL.
407 BOOL WINAPI QueryWorkingSet(HANDLE hProcess, LPVOID pv, DWORD cb)
409 FIXME("(hProcess=0x%08x, %p, %ld)\n", hProcess, pv, cb);
411 if(pv && cb)
412 ((DWORD *) pv)[0] = 0; /* Empty WorkingSet */
414 return TRUE;