Commit 726027d6 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

user32: Return empty string from LoadStringW() if resource is not found.

parent a3287287
......@@ -161,12 +161,13 @@ INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id,
if(buffer == NULL)
return 0;
/* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
(LPWSTR)RT_STRING );
if (!hrsrc) return 0;
hmem = LoadResource( instance, hrsrc );
if (!hmem) return 0;
if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING )) ||
!(hmem = LoadResource( instance, hrsrc )))
{
TRACE( "Failed to load string.\n" );
if (buflen > 0) buffer[0] = 0;
return 0;
}
p = LockResource(hmem);
string_num = resource_id & 0x000f;
......
......@@ -120,6 +120,33 @@ static void test_LoadStringW(void)
winetest_pop_context();
}
}
/* Test missing resource. */
SetLastError(0xdeadbeef);
memset(returnedstringw, 0xcc, sizeof(returnedstringw));
length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, ARRAY_SIZE(returnedstringw));
ok(!length1, "got %d.\n", length1);
ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_FOUND) /* Win7 */,
"got %lu.\n", GetLastError());
ok(!returnedstringw[0], "got %#x.\n", returnedstringw[0]);
ok(returnedstringw[1] == 0xcccc, "got %#x.\n", returnedstringw[1]);
SetLastError(0xdeadbeef);
memset(returnedstringw, 0xcc, sizeof(returnedstringw));
length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, 0);
ok(!length1, "got %d.\n", length1);
ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_LOADED) /* Win7 */,
"got %lu.\n", GetLastError());
ok(returnedstringw[0] == 0xcccc, "got %#x.\n", returnedstringw[1]);
SetLastError(0xdeadbeef);
memset(returnedstringw, 0xcc, sizeof(returnedstringw));
length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, 1);
ok(!length1, "got %d.\n", length1);
ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_LOADED) /* Win7 */,
"got %lu.\n", GetLastError());
ok(!returnedstringw[0], "got %#x.\n", returnedstringw[0]);
ok(returnedstringw[1] == 0xcccc, "got %#x.\n", returnedstringw[1]);
}
static void test_LoadStringA (void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment