Commit 4fe6460a authored by Akihiro Sagawa's avatar Akihiro Sagawa Committed by Alexandre Julliard

advapi32: Return required buffer size in RegLoadMUIString.

parent 2d9a7cd3
...@@ -3112,7 +3112,7 @@ LSTATUS WINAPI RegOpenUserClassesRoot( ...@@ -3112,7 +3112,7 @@ LSTATUS WINAPI RegOpenUserClassesRoot(
* avoid importing user32, which is higher level than advapi32. Helper for * avoid importing user32, which is higher level than advapi32. Helper for
* RegLoadMUIString. * RegLoadMUIString.
*/ */
static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars) static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars, UINT *reqChars)
{ {
HGLOBAL hMemory; HGLOBAL hMemory;
HRSRC hResource; HRSRC hResource;
...@@ -3133,6 +3133,7 @@ static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cM ...@@ -3133,6 +3133,7 @@ static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cM
/* Strings are length-prefixed. Lowest nibble of resId is an index. */ /* Strings are length-prefixed. Lowest nibble of resId is an index. */
idxString = resId & 0xf; idxString = resId & 0xf;
while (idxString--) pString += *pString + 1; while (idxString--) pString += *pString + 1;
*reqChars = *pString + 1;
/* If no buffer is given, return here. */ /* If no buffer is given, return here. */
if (!pwszBuffer) return ERROR_MORE_DATA; if (!pwszBuffer) return ERROR_MORE_DATA;
...@@ -3221,6 +3222,8 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer ...@@ -3221,6 +3222,8 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
result = ERROR_SUCCESS; result = ERROR_SUCCESS;
if (*pwszExpandedBuffer != '@') { /* '@' is the prefix for resource based string entries. */ if (*pwszExpandedBuffer != '@') { /* '@' is the prefix for resource based string entries. */
lstrcpynW(pwszBuffer, pwszExpandedBuffer, cbBuffer / sizeof(WCHAR)); lstrcpynW(pwszBuffer, pwszExpandedBuffer, cbBuffer / sizeof(WCHAR));
if (pcbData)
*pcbData = (strlenW(pwszExpandedBuffer) + 1) * sizeof(WCHAR);
} else { } else {
WCHAR *pComma = strrchrW(pwszExpandedBuffer, ','), *pNewBuffer; WCHAR *pComma = strrchrW(pwszExpandedBuffer, ','), *pNewBuffer;
const WCHAR backslashW[] = {'\\',0}; const WCHAR backslashW[] = {'\\',0};
...@@ -3264,7 +3267,10 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer ...@@ -3264,7 +3267,10 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
hModule = LoadLibraryExW(pwszTempBuffer, NULL, hModule = LoadLibraryExW(pwszTempBuffer, NULL,
LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE); LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
if (hModule) { if (hModule) {
result = load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR)); DWORD reqChars;
result = load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR), &reqChars);
if (pcbData && (result == ERROR_SUCCESS || result == ERROR_MORE_DATA))
*pcbData = reqChars * sizeof(WCHAR);
FreeLibrary(hModule); FreeLibrary(hModule);
} }
else else
......
...@@ -3892,7 +3892,7 @@ static void test_RegLoadMUIString(void) ...@@ -3892,7 +3892,7 @@ static void test_RegLoadMUIString(void)
size = 0xdeadbeef; size = 0xdeadbeef;
ret = pRegLoadMUIStringW(hkey, tz_valueW, NULL, 0, &size, 0, NULL); ret = pRegLoadMUIStringW(hkey, tz_valueW, NULL, 0, &size, 0, NULL);
ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret); ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
todo_wine ok(size == text_size, "got %u, expected %u\n", size, text_size); ok(size == text_size, "got %u, expected %u\n", size, text_size);
memset(bufW, 0xff, sizeof(bufW)); memset(bufW, 0xff, sizeof(bufW));
ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)+1, &size, 0, NULL); ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)+1, &size, 0, NULL);
...@@ -3903,7 +3903,7 @@ static void test_RegLoadMUIString(void) ...@@ -3903,7 +3903,7 @@ static void test_RegLoadMUIString(void)
memset(bufW, 0xff, sizeof(bufW)); memset(bufW, 0xff, sizeof(bufW));
ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, &size, 0, NULL); ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, &size, 0, NULL);
todo_wine ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret); todo_wine ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
todo_wine ok(size == text_size || broken(size == text_size + sizeof(WCHAR) /* vista */), ok(size == text_size || broken(size == text_size + sizeof(WCHAR) /* vista */),
"got %u, expected %u\n", size, text_size); "got %u, expected %u\n", size, text_size);
todo_wine ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]); todo_wine ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]);
...@@ -3911,9 +3911,8 @@ static void test_RegLoadMUIString(void) ...@@ -3911,9 +3911,8 @@ static void test_RegLoadMUIString(void)
memset(bufW, 0xff, sizeof(bufW)); memset(bufW, 0xff, sizeof(bufW));
ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, NULL); ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, NULL);
ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret); ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret);
todo_wine ok(size == text_size, "got %u, expected %u\n", size, text_size); ok(size == text_size, "got %u, expected %u\n", size, text_size);
size = min(size, sizeof(bufW)); ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
todo_wine ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR))); wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR)));
ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, NULL); ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, NULL);
...@@ -3926,9 +3925,8 @@ static void test_RegLoadMUIString(void) ...@@ -3926,9 +3925,8 @@ static void test_RegLoadMUIString(void)
memset(bufW, 0xff, sizeof(bufW)); memset(bufW, 0xff, sizeof(bufW));
ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, sysdirW); ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, sysdirW);
ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret); ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret);
todo_wine ok(size == text_size, "got %u, expected %u\n", size, text_size); ok(size == text_size, "got %u, expected %u\n", size, text_size);
size = min(size, sizeof(bufW)); ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
todo_wine ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR))); wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR)));
ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, sysdir); ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, sysdir);
......
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