psapi: Implement GetProcessImageNameW.

This commit is contained in:
Mikołaj Zalewski 2009-04-06 22:32:33 +02:00 committed by Alexandre Julliard
parent 33a0062e0f
commit 666c0a57cc
2 changed files with 58 additions and 21 deletions

View File

@ -507,8 +507,11 @@ DWORD WINAPI GetProcessImageFileNameA( HANDLE process, LPSTR file, DWORD size )
*/ */
DWORD WINAPI GetProcessImageFileNameW( HANDLE process, LPWSTR file, DWORD size ) DWORD WINAPI GetProcessImageFileNameW( HANDLE process, LPWSTR file, DWORD size )
{ {
FIXME("(%p, %p, %d) stub\n", process, file, size ); BOOL success = QueryFullProcessImageNameW(process, PROCESS_NAME_NATIVE, file, &size);
return 0; if (success)
return size;
else
return 0;
} }
/*********************************************************************** /***********************************************************************

View File

@ -21,10 +21,17 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "wine/test.h"
#include "windows.h" #include "windows.h"
#include "wine/test.h"
#include "psapi.h" #include "psapi.h"
#define expect_eq_d(expected, actual) \
do { \
int value = (actual); \
ok((expected) == value, "Expected " #actual " to be %d (" #expected ") is %d\n", \
(expected), value); \
} while (0)
#define PSAPI_GET_PROC(func) \ #define PSAPI_GET_PROC(func) \
p ## func = (void*)GetProcAddress(hpsapi, #func); \ p ## func = (void*)GetProcAddress(hpsapi, #func); \
if(!p ## func) { \ if(!p ## func) { \
@ -63,6 +70,7 @@ static DWORD (WINAPI *pGetModuleFileNameExA)(HANDLE, HMODULE, LPSTR, DWORD);
static BOOL (WINAPI *pGetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD); static BOOL (WINAPI *pGetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD);
static DWORD (WINAPI *pGetMappedFileNameA)(HANDLE, LPVOID, LPSTR, DWORD); static DWORD (WINAPI *pGetMappedFileNameA)(HANDLE, LPVOID, LPSTR, DWORD);
static DWORD (WINAPI *pGetProcessImageFileNameA)(HANDLE, LPSTR, DWORD); static DWORD (WINAPI *pGetProcessImageFileNameA)(HANDLE, LPSTR, DWORD);
static DWORD (WINAPI *pGetProcessImageFileNameW)(HANDLE, LPWSTR, DWORD);
static BOOL (WINAPI *pGetProcessMemoryInfo)(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD); static BOOL (WINAPI *pGetProcessMemoryInfo)(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
static BOOL (WINAPI *pGetWsChanges)(HANDLE, PPSAPI_WS_WATCH_INFORMATION, DWORD); static BOOL (WINAPI *pGetWsChanges)(HANDLE, PPSAPI_WS_WATCH_INFORMATION, DWORD);
static BOOL (WINAPI *pInitializeProcessForWsWatch)(HANDLE); static BOOL (WINAPI *pInitializeProcessForWsWatch)(HANDLE);
@ -84,6 +92,8 @@ static BOOL InitFunctionPtrs(HMODULE hpsapi)
/* GetProcessImageFileName is not exported on NT4 */ /* GetProcessImageFileName is not exported on NT4 */
pGetProcessImageFileNameA = pGetProcessImageFileNameA =
(void *)GetProcAddress(hpsapi, "GetProcessImageFileNameA"); (void *)GetProcAddress(hpsapi, "GetProcessImageFileNameA");
pGetProcessImageFileNameW =
(void *)GetProcAddress(hpsapi, "GetProcessImageFileNameW");
return TRUE; return TRUE;
} }
@ -166,6 +176,7 @@ static void test_GetProcessImageFileName(void)
{ {
HMODULE hMod = GetModuleHandle(NULL); HMODULE hMod = GetModuleHandle(NULL);
char szImgPath[MAX_PATH], szMapPath[MAX_PATH]; char szImgPath[MAX_PATH], szMapPath[MAX_PATH];
WCHAR szImgPathW[MAX_PATH];
DWORD ret; DWORD ret;
if(pGetProcessImageFileNameA == NULL) if(pGetProcessImageFileNameA == NULL)
@ -175,26 +186,49 @@ static void test_GetProcessImageFileName(void)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
if(!pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath))) if(!pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath)))
{ {
if(GetLastError() == ERROR_INVALID_FUNCTION) if(GetLastError() == ERROR_INVALID_FUNCTION) {
win_skip("GetProcessImageFileName not implemented\n"); win_skip("GetProcessImageFileName not implemented\n");
else if(GetLastError() == 0xdeadbeef) return;
ok(0, "failed without error code\n"); }
else
ok(0, "failed with %d\n", GetLastError());
return; if(GetLastError() == 0xdeadbeef)
todo_wine ok(0, "failed without error code\n");
else
todo_wine ok(0, "failed with %d\n", GetLastError());
} }
w32_err(pGetProcessImageFileNameA(NULL, szImgPath, sizeof(szImgPath)), ERROR_INVALID_HANDLE); todo_wine w32_err(pGetProcessImageFileNameA(NULL, szImgPath, sizeof(szImgPath)), ERROR_INVALID_HANDLE);
w32_err(pGetProcessImageFileNameA(hpSR, szImgPath, sizeof(szImgPath)), ERROR_ACCESS_DENIED); todo_wine w32_err(pGetProcessImageFileNameA(hpSR, szImgPath, sizeof(szImgPath)), ERROR_ACCESS_DENIED);
w32_err(pGetProcessImageFileNameA(hpQI, szImgPath, 0), ERROR_INSUFFICIENT_BUFFER); todo_wine w32_err(pGetProcessImageFileNameA(hpQI, szImgPath, 0), ERROR_INSUFFICIENT_BUFFER);
if(!w32_suc(ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath))) || todo_wine
!w32_suc(pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath)))) if(w32_suc(ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath))) &&
return; w32_suc(pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath)))) {
/* Windows returns 2*strlen-1 */ /* Windows returns 2*strlen-1 */
ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret); ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret);
ok(!strcmp(szImgPath, szMapPath), ok(!strcmp(szImgPath, szMapPath),
"szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath); "szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath);
}
w32_err(pGetProcessImageFileNameW(NULL, szImgPathW, sizeof(szImgPathW)), ERROR_INVALID_HANDLE);
/* no information about correct buffer size returned: */
w32_err(pGetProcessImageFileNameW(hpQI, szImgPathW, 0), ERROR_INSUFFICIENT_BUFFER);
w32_err(pGetProcessImageFileNameW(hpQI, NULL, 0), ERROR_INSUFFICIENT_BUFFER);
/* correct call */
memset(szImgPathW, 0xff, sizeof(szImgPathW));
ret = pGetProcessImageFileNameW(hpQI, szImgPathW, sizeof(szImgPathW)/sizeof(WCHAR));
ok(ret > 0, "GetProcessImageFileNameW should have succeeded.\n");
ok(szImgPathW[0] == '\\', "GetProcessImageFileNameW should have returned an NT path.\n");
expect_eq_d(lstrlenW(szImgPathW), ret);
/* boundary values of 'size' */
w32_err(pGetProcessImageFileNameW(hpQI, szImgPathW, ret), ERROR_INSUFFICIENT_BUFFER);
memset(szImgPathW, 0xff, sizeof(szImgPathW));
ret = pGetProcessImageFileNameW(hpQI, szImgPathW, ret + 1);
ok(ret > 0, "GetProcessImageFileNameW should have succeeded.\n");
ok(szImgPathW[0] == '\\', "GetProcessImageFileNameW should have returned an NT path.\n");
expect_eq_d(lstrlenW(szImgPathW), ret);
} }
static void test_GetModuleFileNameEx(void) static void test_GetModuleFileNameEx(void)
@ -309,7 +343,7 @@ START_TEST(psapi_main)
test_GetModuleInformation(); test_GetModuleInformation();
test_GetProcessMemoryInfo(); test_GetProcessMemoryInfo();
todo_wine test_GetMappedFileName(); todo_wine test_GetMappedFileName();
todo_wine test_GetProcessImageFileName(); test_GetProcessImageFileName();
test_GetModuleFileNameEx(); test_GetModuleFileNameEx();
test_GetModuleBaseName(); test_GetModuleBaseName();
test_ws_functions(); test_ws_functions();