[PATCH] make LoadStringW pass conformance tests
Christopher Berner
raccoonone at procyongames.com
Wed Mar 5 11:28:26 CST 2008
---
dlls/crypt32/oid.c | 3 ++-
dlls/hhctrl.ocx/help.c | 4 ++--
dlls/mpr/wnet.c | 3 ++-
dlls/user32/resource.c | 14 +++++++++++++-
dlls/user32/tests/resource.c | 28 ++++++++++------------------
5 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/dlls/crypt32/oid.c b/dlls/crypt32/oid.c
index 5d17997..edd9732 100644
--- a/dlls/crypt32/oid.c
+++ b/dlls/crypt32/oid.c
@@ -1402,8 +1402,9 @@ static void init_oid_info(HINSTANCE hinst)
}
else
{
+ LPWSTR junkpointer; /* third argument cannot be NULL, to receive length of resource from LoadStringW */
int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
- NULL, 0);
+ (LPWSTR)&junkpointer, 0);
if (len)
{
diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c
index 3f6a080..6af7099 100644
--- a/dlls/hhctrl.ocx/help.c
+++ b/dlls/hhctrl.ocx/help.c
@@ -50,10 +50,10 @@ static const WCHAR szEmpty[] = {0};
/* Loads a string from the resource file */
static LPWSTR HH_LoadString(DWORD dwID)
{
- LPWSTR string = NULL;
+ LPWSTR string = NULL, junkpointer;
int iSize;
- iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
+ iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&junkpointer, 0);
iSize += 2; /* some strings (tab text) needs double-null termination */
string = heap_alloc(iSize * sizeof(WCHAR));
diff --git a/dlls/mpr/wnet.c b/dlls/mpr/wnet.c
index 36fb93c..f9613d6 100644
--- a/dlls/mpr/wnet.c
+++ b/dlls/mpr/wnet.c
@@ -279,9 +279,10 @@ void wnetInit(HINSTANCE hInstDll)
{
PWSTR ptrPrev;
int entireNetworkLen;
+ LPWSTR junkpointer;
entireNetworkLen = LoadStringW(hInstDll,
- IDS_ENTIRENETWORK, NULL, 0);
+ IDS_ENTIRENETWORK, (LPWSTR)&junkpointer, 0);
providerTable->entireNetwork = HeapAlloc(
GetProcessHeap(), 0, (entireNetworkLen + 1) *
sizeof(WCHAR));
diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c
index 9eed0e8..7813310 100644
--- a/dlls/user32/resource.c
+++ b/dlls/user32/resource.c
@@ -364,10 +364,14 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
WCHAR *p;
int string_num;
int i;
+ int length;
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 );
@@ -381,8 +385,16 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
p += *p + 1;
TRACE("strlen = %d\n", (int)*p );
+ length = (int)*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 length;
+ }
- if (buffer == NULL) return *p;
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 0fd77b7..2b72535 100644
--- a/dlls/user32/tests/resource.c
+++ b/dlls/user32/tests/resource.c
@@ -43,13 +43,10 @@ static void test_LoadStringW(void)
length1 = LoadStringW(hInst, 2, (WCHAR *) &resourcepointer, 0); /* get pointer to resource. */
length2 = LoadStringW(hInst, 2, returnedstringw, sizeof(returnedstringw) /sizeof(WCHAR)); /* get resource string */
ok(length2 > 0, "LoadStringW failed to load resource 2, ret %d, err %d\n", length2, GetLastError());
- todo_wine
- {
- ok(length1 == length2, "LoadStringW returned different values dependent on buflen. ret1 %d, ret2 %d\n",
- length1, length2);
- ok(length1 > 0 && resourcepointer != NULL, "LoadStringW failed to get pointer to resource 2, ret %d, err %d\n",
- length1, GetLastError());
- }
+ ok(length1 == length2, "LoadStringW returned different values dependent on buflen. ret1 %d, ret2 %d\n",
+ length1, length2);
+ ok(length1 > 0 && resourcepointer != NULL, "LoadStringW failed to get pointer to resource 2, ret %d, err %d\n",
+ length1, GetLastError());
/* Copy the resource since it is not '\0' terminated, and add '\0' to the end */
if(resourcepointer != NULL) /* Check that the resource pointer was loaded to avoid access violation */
@@ -62,17 +59,12 @@ static void test_LoadStringW(void)
ok(!memcmp(copiedstringw, returnedstringw, (length2 + 1)*sizeof(WCHAR)),
"strings don't match: returnedstring = %s, copiedstring = %s\n", returnedstring, copiedstring);
}
- todo_wine
- {
- /* 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);
- }
+ /* 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)
--
1.5.2.5
--------------080401050008040602060902--
More information about the wine-patches
mailing list