[PATCH] Fixes for LoadStringW, and conformance test
Christopher Berner
raccoonone at procyongames.com
Mon Jan 21 14:02:59 CST 2008
---
dlls/user32/resource.c | 14 +++++++++++++-
dlls/user32/tests/resource.c | 38 ++++++++++++++++++++++++++++++++++++++
dlls/user32/tests/resource.rc | 1 +
3 files changed, 52 insertions(+), 1 deletions(-)
diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c
index b9a51ae..c71b98a 100644
--- a/dlls/user32/resource.c
+++ b/dlls/user32/resource.c
@@ -363,10 +363,14 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
WCHAR *p;
int string_num;
int i;
+ int strlen;
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
instance, resource_id, buffer, buflen);
+ if (buffer == NULL)
+ return 0;
+
/* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
(LPWSTR)RT_STRING );
@@ -379,9 +383,17 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
for (i = 0; i < string_num; i++)
p += *p + 1;
+ strlen = (int)*p;
TRACE("strlen = %d\n", (int)*p );
- if (buffer == NULL) return *p;
+ /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
+ it is assumed that buffer is actually a (LPWSTR *) */
+ if(buflen == 0)
+ {
+ *((LPWSTR *)buffer) = p + 1;
+ return strlen;
+ }
+
i = min(buflen - 1, *p);
if (i > 0) {
memcpy(buffer, p + 1, i * sizeof (WCHAR));
diff --git a/dlls/user32/tests/resource.c b/dlls/user32/tests/resource.c
index 59f86ef..f96f030 100644
--- a/dlls/user32/tests/resource.c
+++ b/dlls/user32/tests/resource.c
@@ -31,6 +31,43 @@ static void init_function_pointers(void)
pPrivateExtractIconsA = (void*)GetProcAddress(hmod, "PrivateExtractIconsA");
}
+static void test_LoadStringW(void)
+{
+ HINSTANCE hInst = GetModuleHandle(NULL);
+ WCHAR copiedstring[128], returnedstring[128], *resourcepointer = NULL;
+ int strlen, strlen2, retvalue;
+
+ /* Check that the string which is returned by LoadStringW matches
+ the string at the pointer returned by LoadStringW when called with buflen = 0 */
+ strlen = LoadStringW(hInst, 2, (WCHAR *) &resourcepointer, 0); /* get pointer to resource. */
+ ok(strlen > 0 && resourcepointer != NULL, "LoadStringW failed to get pointer to resource 2, ret %d, err %d \n",
+ strlen, GetLastError());
+
+ strlen2 = LoadStringW(hInst, 2, returnedstring, sizeof(returnedstring) /sizeof(WCHAR));
+ ok(strlen == strlen2, "LoadStringW returned different values dependent on buflen. ret1 %d, ret2 %d \n",
+ strlen, strlen2);
+ ok(strlen2 > 0, "LoadStringW failed to load resource 2, ret %d, err %d \n", strlen2, GetLastError());
+
+ /* Copy the resource since it is not '\0' terminated, and add '\0' to the end */
+ if(resourcepointer != NULL)
+ {
+ memcpy(copiedstring, resourcepointer, strlen * sizeof(WCHAR));
+ copiedstring[strlen] = '\0';
+ }
+ /* check that strings match */
+ ok(!memcmp(copiedstring, returnedstring, (strlen + 1)*sizeof(WCHAR)),
+ "LoadStringW returned a string that does not match the string pointed to by the pointer it returned. \
+ returnedstring = %ls, copiedstring = %ls", (wchar_t *)returnedstring, (wchar_t *)copiedstring);
+ /* check that calling LoadStringW with buffer = NULL returns zero */
+ retvalue = LoadStringW(hInst, 2, NULL, 0);
+ ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d",
+ retvalue);
+ /* check again, with a different buflen value, that calling LoadStringW with buffer = NULL returns zero */
+ retvalue = LoadStringW(hInst, 2, NULL, 128);
+ ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d",
+ retvalue);
+}
+
static void test_LoadStringA (void)
{
HINSTANCE hInst = GetModuleHandle (NULL);
@@ -317,6 +354,7 @@ START_TEST(resource)
{
init_function_pointers();
test_LoadStringA ();
+ test_LoadStringW();
test_accel1();
test_accel2();
test_PrivateExtractIcons();
diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc
index 31ec68f..f01c6f5 100644
--- a/dlls/user32/tests/resource.rc
+++ b/dlls/user32/tests/resource.rc
@@ -41,6 +41,7 @@ STRINGTABLE
{
0 "String resource"
1 "Another string resource"
+ 2 L"This is a wide string resource"
65534 "Test high id"
}
--
1.5.2.5
--------------090809010901030103040105--
More information about the wine-patches
mailing list