kernel32: Reset LastError if GetModuleFileName() succeeds.

This commit is contained in:
Francois Gouget 2011-10-03 23:38:29 +02:00 committed by Alexandre Julliard
parent 8abe262fd2
commit 8e67930bd7
2 changed files with 11 additions and 0 deletions

View file

@ -648,7 +648,10 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size
len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
memcpy(lpFileName, pldr->FullDllName.Buffer, len * sizeof(WCHAR));
if (len < size)
{
lpFileName[len] = '\0';
SetLastError( 0 );
}
else
SetLastError( ERROR_INSUFFICIENT_BUFFER );
}

View file

@ -44,13 +44,21 @@ static void testGetModuleFileName(const char* name)
/* first test, with enough space in buffer */
memset(bufA, '-', sizeof(bufA));
SetLastError(0xdeadbeef);
len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA));
ok(GetLastError() == ERROR_SUCCESS ||
broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
"LastError was not reset: %u\n", GetLastError());
ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
if (is_unicode_enabled)
{
memset(bufW, '-', sizeof(bufW));
SetLastError(0xdeadbeef);
len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR));
ok(GetLastError() == ERROR_SUCCESS ||
broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
"LastError was not reset: %u\n", GetLastError());
ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
}