[PATCH 0/1] MR9733: sapi: Implement SpDataKey::EnumValues()
Fixes an issue with programs that infinitely read for `SPERR_NO_MORE_ITEMS`, such as Scrivener. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9733
From: "J. Pfeiffer" <jade@pfeiffer.codes> --- dlls/sapi/tests/token.c | 14 ++++++++++++++ dlls/sapi/token.c | 43 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dlls/sapi/tests/token.c b/dlls/sapi/tests/token.c index c7067718c45..8ec564bbf38 100644 --- a/dlls/sapi/tests/token.c +++ b/dlls/sapi/tests/token.c @@ -54,11 +54,17 @@ static void test_data_key(void) hr = ISpRegDataKey_SetStringValue( data_key, L"Voice", L"Test" ); ok( hr == E_HANDLE, "got %08lx\n", hr ); + hr = ISpRegDataKey_EnumValues(data_key, 0, &value); + ok( hr == E_HANDLE, "got %08lx\n", hr ); + hr = ISpRegDataKey_SetKey( data_key, key, FALSE ); ok( hr == S_OK, "got %08lx\n", hr ); hr = ISpRegDataKey_SetKey( data_key, key, FALSE ); ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr ); + hr = ISpRegDataKey_EnumValues(data_key, 0, &value); + ok( hr == SPERR_NO_MORE_ITEMS, "got %08lx\n", hr ); + hr = ISpRegDataKey_GetStringValue( data_key, L"Voice", &value ); ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr ); @@ -73,6 +79,14 @@ static void test_data_key(void) ok( !wcscmp( value, L"Test" ), "got %s\n", wine_dbgstr_w(value) ); CoTaskMemFree( value ); + hr = ISpRegDataKey_EnumValues(data_key, 0, &value); + ok( hr == S_OK, "got %08lx\n", hr ); + ok( !wcscmp( value, L"Voice" ), "got %s\n", wine_dbgstr_w(value) ); + CoTaskMemFree( value ); + + hr = ISpRegDataKey_EnumValues(data_key, 1, &value); + ok( hr == SPERR_NO_MORE_ITEMS, "got %08lx\n", hr ); + hr = ISpRegDataKey_OpenKey( data_key, L"Testing", &sub ); ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr ); diff --git a/dlls/sapi/token.c b/dlls/sapi/token.c index 65d35dc96ff..ec6ebeb47d4 100644 --- a/dlls/sapi/token.c +++ b/dlls/sapi/token.c @@ -275,8 +275,47 @@ static HRESULT WINAPI data_key_EnumKeys( ISpRegDataKey *iface, static HRESULT WINAPI data_key_EnumValues( ISpRegDataKey *iface, ULONG index, LPWSTR *value ) { - FIXME( "stub\n" ); - return E_NOTIMPL; + struct data_key *This = impl_from_ISpRegDataKey( iface ); + DWORD ret, count, size; + WCHAR _buffer[1]; + WCHAR *content; + + if (!This->key) + return E_HANDLE; + + count = 0; + size = 0; + + ret = RegEnumValueW(This->key, index, _buffer, &count, NULL, NULL, NULL, &size); + if (ret == ERROR_NO_MORE_ITEMS) + { + return SPERR_NO_MORE_ITEMS; + } + else if (ret == ERROR_NOT_ENOUGH_MEMORY) + { + return E_OUTOFMEMORY; + } + else if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) + { + return SPERR_NOT_FOUND; + } + + size = size + sizeof(WCHAR); + count = size / sizeof(WCHAR); + + content = CoTaskMemAlloc(size); + if (!content) + return E_OUTOFMEMORY; + + ret = RegEnumValueW(This->key, index, content, &count, NULL, NULL, NULL, NULL); + if (ret != ERROR_SUCCESS) + { + CoTaskMemFree(content); + return HRESULT_FROM_WIN32(ret); + } + + *value = content; + return S_OK; } static HRESULT WINAPI data_key_SetKey( ISpRegDataKey *iface, -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9733
participants (2)
-
J. Pfeiffer -
Jade Pfeiffer (@Cthuflu)