Christopher Berner : user32: Make LoadStringW pass tests.
Alexandre Julliard
julliard at winehq.org
Tue Mar 11 10:51:48 CDT 2008
Module: wine
Branch: master
Commit: 9978cc9c56f7ec09be2d2a22c2e7fb5d5d1f07be
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9978cc9c56f7ec09be2d2a22c2e7fb5d5d1f07be
Author: Christopher Berner <raccoonone at procyongames.com>
Date: Wed Mar 5 12:28:54 2008 -0800
user32: Make LoadStringW pass tests.
---
dlls/crypt32/oid.c | 10 +++++-----
dlls/hhctrl.ocx/help.c | 9 +++++----
dlls/mpr/wnet.c | 10 ++++++----
dlls/user32/resource.c | 12 +++++++++++-
dlls/user32/tests/resource.c | 29 +++++++++++------------------
5 files changed, 38 insertions(+), 32 deletions(-)
diff --git a/dlls/crypt32/oid.c b/dlls/crypt32/oid.c
index 5d17997..980c750 100644
--- a/dlls/crypt32/oid.c
+++ b/dlls/crypt32/oid.c
@@ -1402,8 +1402,9 @@ static void init_oid_info(HINSTANCE hinst)
}
else
{
+ LPCWSTR stringresource;
int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
- NULL, 0);
+ (LPWSTR)&stringresource, 0);
if (len)
{
@@ -1415,12 +1416,11 @@ static void init_oid_info(HINSTANCE hinst)
memset(info, 0, sizeof(*info));
info->info.cbSize = sizeof(CRYPT_OID_INFO);
info->info.pszOID = oidInfoConstructors[i].pszOID;
- info->info.pwszName =
- (LPWSTR)((LPBYTE)info + sizeof(struct OIDInfo));
+ info->info.pwszName = (LPWSTR)(info + 1);
info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
info->info.u.Algid = oidInfoConstructors[i].Algid;
- LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
- (LPWSTR)info->info.pwszName, len + 1);
+ memcpy(info + 1, stringresource, len*sizeof(WCHAR));
+ ((LPWSTR)(info + 1))[len] = 0;
if (oidInfoConstructors[i].blob)
{
info->info.ExtraInfo.cbData =
diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c
index 3f6a080..3ee522e 100644
--- a/dlls/hhctrl.ocx/help.c
+++ b/dlls/hhctrl.ocx/help.c
@@ -51,13 +51,14 @@ static const WCHAR szEmpty[] = {0};
static LPWSTR HH_LoadString(DWORD dwID)
{
LPWSTR string = NULL;
+ LPCWSTR stringresource;
int iSize;
- iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
- iSize += 2; /* some strings (tab text) needs double-null termination */
+ iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
- string = heap_alloc(iSize * sizeof(WCHAR));
- LoadStringW(hhctrl_hinstance, dwID, string, iSize);
+ string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
+ memcpy(string, stringresource, iSize*sizeof(WCHAR));
+ string[iSize] = 0;
return string;
}
diff --git a/dlls/mpr/wnet.c b/dlls/mpr/wnet.c
index 17e8195..32bc255 100644
--- a/dlls/mpr/wnet.c
+++ b/dlls/mpr/wnet.c
@@ -279,16 +279,18 @@ void wnetInit(HINSTANCE hInstDll)
{
PWSTR ptrPrev;
int entireNetworkLen;
+ LPCWSTR stringresource;
entireNetworkLen = LoadStringW(hInstDll,
- IDS_ENTIRENETWORK, NULL, 0);
+ IDS_ENTIRENETWORK, (LPWSTR)&stringresource, 0);
providerTable->entireNetwork = HeapAlloc(
GetProcessHeap(), 0, (entireNetworkLen + 1) *
sizeof(WCHAR));
if (providerTable->entireNetwork)
- LoadStringW(hInstDll, IDS_ENTIRENETWORK,
- providerTable->entireNetwork,
- entireNetworkLen + 1);
+ {
+ memcpy(providerTable->entireNetwork, stringresource, entireNetworkLen*sizeof(WCHAR));
+ providerTable->entireNetwork[entireNetworkLen] = 0;
+ }
providerTable->numAllocated = numToAllocate;
for (ptr = providers; ptr; )
{
diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c
index 9eed0e8..cbdb4ea 100644
--- a/dlls/user32/resource.c
+++ b/dlls/user32/resource.c
@@ -368,6 +368,9 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
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 );
@@ -382,7 +385,14 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
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 *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 7be82ad..99fc24f 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,13 @@ 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\n",
- 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\n",
- 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\n", 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\n", retvalue);
}
static void test_LoadStringA (void)
More information about the wine-cvs
mailing list