advapi32: Improve load_string to return error code.

Signed-off-by: Akihiro Sagawa <sagawa.aki@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Akihiro Sagawa 2019-05-09 22:07:30 +09:00 committed by Alexandre Julliard
parent ec716f74d7
commit bfdfe85229
2 changed files with 12 additions and 9 deletions

View file

@ -3112,7 +3112,7 @@ LSTATUS WINAPI RegOpenUserClassesRoot(
* avoid importing user32, which is higher level than advapi32. Helper for
* RegLoadMUIString.
*/
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
{
HGLOBAL hMemory;
HRSRC hResource;
@ -3125,17 +3125,17 @@ static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMa
/* Load the resource into memory and get a pointer to it. */
hResource = FindResourceW(hModule, MAKEINTRESOURCEW(LOWORD(resId >> 4) + 1), (LPWSTR)RT_STRING);
if (!hResource) return 0;
if (!hResource) return ERROR_FILE_NOT_FOUND;
hMemory = LoadResource(hModule, hResource);
if (!hMemory) return 0;
if (!hMemory) return ERROR_FILE_NOT_FOUND;
pString = LockResource(hMemory);
/* Strings are length-prefixed. Lowest nibble of resId is an index. */
idxString = resId & 0xf;
while (idxString--) pString += *pString + 1;
/* If no buffer is given, return length of the string. */
if (!pwszBuffer) return *pString;
/* If no buffer is given, return here. */
if (!pwszBuffer) return ERROR_MORE_DATA;
/* Else copy over the string, respecting the buffer size. */
cMaxChars = (*pString < cMaxChars) ? *pString : (cMaxChars - 1);
@ -3144,7 +3144,7 @@ static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMa
pwszBuffer[cMaxChars] = '\0';
}
return cMaxChars;
return ERROR_SUCCESS;
}
/******************************************************************************
@ -3263,9 +3263,12 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
/* Load the file */
hModule = LoadLibraryExW(pwszTempBuffer, NULL,
LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
if (!hModule || !load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR)))
if (hModule) {
result = load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR));
FreeLibrary(hModule);
}
else
result = ERROR_BADKEY;
FreeLibrary(hModule);
}
cleanup:

View file

@ -3891,7 +3891,7 @@ static void test_RegLoadMUIString(void)
size = 0xdeadbeef;
ret = pRegLoadMUIStringW(hkey, tz_valueW, NULL, 0, &size, 0, NULL);
todo_wine 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);
memset(bufW, 0xff, sizeof(bufW));