Commit 9978cc9c authored by Christopher Berner's avatar Christopher Berner Committed by Alexandre Julliard

user32: Make LoadStringW pass tests.

parent 17bf0d91
...@@ -1402,8 +1402,9 @@ static void init_oid_info(HINSTANCE hinst) ...@@ -1402,8 +1402,9 @@ static void init_oid_info(HINSTANCE hinst)
} }
else else
{ {
LPCWSTR stringresource;
int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName, int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
NULL, 0); (LPWSTR)&stringresource, 0);
if (len) if (len)
{ {
...@@ -1415,12 +1416,11 @@ static void init_oid_info(HINSTANCE hinst) ...@@ -1415,12 +1416,11 @@ static void init_oid_info(HINSTANCE hinst)
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->info.cbSize = sizeof(CRYPT_OID_INFO); info->info.cbSize = sizeof(CRYPT_OID_INFO);
info->info.pszOID = oidInfoConstructors[i].pszOID; info->info.pszOID = oidInfoConstructors[i].pszOID;
info->info.pwszName = info->info.pwszName = (LPWSTR)(info + 1);
(LPWSTR)((LPBYTE)info + sizeof(struct OIDInfo));
info->info.dwGroupId = oidInfoConstructors[i].dwGroupId; info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
info->info.u.Algid = oidInfoConstructors[i].Algid; info->info.u.Algid = oidInfoConstructors[i].Algid;
LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName, memcpy(info + 1, stringresource, len*sizeof(WCHAR));
(LPWSTR)info->info.pwszName, len + 1); ((LPWSTR)(info + 1))[len] = 0;
if (oidInfoConstructors[i].blob) if (oidInfoConstructors[i].blob)
{ {
info->info.ExtraInfo.cbData = info->info.ExtraInfo.cbData =
......
...@@ -51,13 +51,14 @@ static const WCHAR szEmpty[] = {0}; ...@@ -51,13 +51,14 @@ static const WCHAR szEmpty[] = {0};
static LPWSTR HH_LoadString(DWORD dwID) static LPWSTR HH_LoadString(DWORD dwID)
{ {
LPWSTR string = NULL; LPWSTR string = NULL;
LPCWSTR stringresource;
int iSize; int iSize;
iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0); iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
iSize += 2; /* some strings (tab text) needs double-null termination */
string = heap_alloc(iSize * sizeof(WCHAR)); string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
LoadStringW(hhctrl_hinstance, dwID, string, iSize); memcpy(string, stringresource, iSize*sizeof(WCHAR));
string[iSize] = 0;
return string; return string;
} }
......
...@@ -279,16 +279,18 @@ void wnetInit(HINSTANCE hInstDll) ...@@ -279,16 +279,18 @@ void wnetInit(HINSTANCE hInstDll)
{ {
PWSTR ptrPrev; PWSTR ptrPrev;
int entireNetworkLen; int entireNetworkLen;
LPCWSTR stringresource;
entireNetworkLen = LoadStringW(hInstDll, entireNetworkLen = LoadStringW(hInstDll,
IDS_ENTIRENETWORK, NULL, 0); IDS_ENTIRENETWORK, (LPWSTR)&stringresource, 0);
providerTable->entireNetwork = HeapAlloc( providerTable->entireNetwork = HeapAlloc(
GetProcessHeap(), 0, (entireNetworkLen + 1) * GetProcessHeap(), 0, (entireNetworkLen + 1) *
sizeof(WCHAR)); sizeof(WCHAR));
if (providerTable->entireNetwork) if (providerTable->entireNetwork)
LoadStringW(hInstDll, IDS_ENTIRENETWORK, {
providerTable->entireNetwork, memcpy(providerTable->entireNetwork, stringresource, entireNetworkLen*sizeof(WCHAR));
entireNetworkLen + 1); providerTable->entireNetwork[entireNetworkLen] = 0;
}
providerTable->numAllocated = numToAllocate; providerTable->numAllocated = numToAllocate;
for (ptr = providers; ptr; ) for (ptr = providers; ptr; )
{ {
......
...@@ -368,6 +368,9 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id, ...@@ -368,6 +368,9 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n", TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
instance, resource_id, buffer, buflen); instance, resource_id, buffer, buflen);
if(buffer == NULL)
return 0;
/* Use loword (incremented by 1) as resourceid */ /* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
(LPWSTR)RT_STRING ); (LPWSTR)RT_STRING );
...@@ -382,7 +385,14 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id, ...@@ -382,7 +385,14 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
TRACE("strlen = %d\n", (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 *p;
}
i = min(buflen - 1, *p); i = min(buflen - 1, *p);
if (i > 0) { if (i > 0) {
memcpy(buffer, p + 1, i * sizeof (WCHAR)); memcpy(buffer, p + 1, i * sizeof (WCHAR));
......
...@@ -43,13 +43,10 @@ static void test_LoadStringW(void) ...@@ -43,13 +43,10 @@ static void test_LoadStringW(void)
length1 = LoadStringW(hInst, 2, (WCHAR *) &resourcepointer, 0); /* get pointer to resource. */ length1 = LoadStringW(hInst, 2, (WCHAR *) &resourcepointer, 0); /* get pointer to resource. */
length2 = LoadStringW(hInst, 2, returnedstringw, sizeof(returnedstringw) /sizeof(WCHAR)); /* get resource string */ 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()); 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 == length2, "LoadStringW returned different values dependent on buflen. ret1 %d, ret2 %d\n", ok(length1 > 0 && resourcepointer != NULL, "LoadStringW failed to get pointer to resource 2, ret %d, err %d\n",
length1, length2); length1, GetLastError());
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 */ /* 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 */ if(resourcepointer != NULL) /* Check that the resource pointer was loaded to avoid access violation */
...@@ -62,17 +59,13 @@ static void test_LoadStringW(void) ...@@ -62,17 +59,13 @@ static void test_LoadStringW(void)
ok(!memcmp(copiedstringw, returnedstringw, (length2 + 1)*sizeof(WCHAR)), ok(!memcmp(copiedstringw, returnedstringw, (length2 + 1)*sizeof(WCHAR)),
"strings don't match: returnedstring = %s, copiedstring = %s\n", returnedstring, copiedstring); "strings don't match: returnedstring = %s, copiedstring = %s\n", returnedstring, copiedstring);
} }
todo_wine
{ /* check that calling LoadStringW with buffer = NULL returns zero */
/* check that calling LoadStringW with buffer = NULL returns zero */ retvalue = LoadStringW(hInst, 2, NULL, 0);
retvalue = LoadStringW(hInst, 2, NULL, 0); ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d\n", retvalue);
ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d\n", /* check again, with a different buflen value, that calling LoadStringW with buffer = NULL returns zero */
retvalue); retvalue = LoadStringW(hInst, 2, NULL, 128);
/* check again, with a different buflen value, that calling LoadStringW with buffer = NULL returns zero */ ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d\n", retvalue);
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) 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