[PATCH] shell32: fix two bugs in IQueryAssocations
Theodore Dubois
tblodt at icloud.com
Fri Feb 5 15:07:33 CST 2016
Basically, returns the correct value for
ASSOCSTR_FRIENDLYDOCNAME and ASSOCSTR_DEFAULTICON
when passed a ProgID instead of a file extension.
Also adds a test to make sure this works.
Signed-off-by: Theodore Dubois <tblodt at icloud.com>
---
dlls/shell32/assoc.c | 60 ++++++++++------------------------------------
dlls/shell32/tests/assoc.c | 4 +++-
2 files changed, 16 insertions(+), 48 deletions(-)
diff --git a/dlls/shell32/assoc.c b/dlls/shell32/assoc.c
index 90d00a8..38b0a2b 100644
--- a/dlls/shell32/assoc.c
+++ b/dlls/shell32/assoc.c
@@ -507,33 +507,12 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
case ASSOCSTR_FRIENDLYDOCNAME:
{
- WCHAR *pszFileType;
- DWORD ret;
- DWORD size;
+ WCHAR *docName;
- hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
+ hr = ASSOC_GetValue(This->hkeyProgID, NULL, (void**)&docName, NULL);
if (FAILED(hr))
return hr;
- size = 0;
- ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
- if (ret == ERROR_SUCCESS)
- {
- WCHAR *docName = HeapAlloc(GetProcessHeap(), 0, size);
- if (docName)
- {
- ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size);
- if (ret == ERROR_SUCCESS)
- hr = ASSOC_ReturnString(flags, pszOut, pcchOut, docName, strlenW(docName) + 1);
- else
- hr = HRESULT_FROM_WIN32(ret);
- HeapFree(GetProcessHeap(), 0, docName);
- }
- else
- hr = E_OUTOFMEMORY;
- }
- else
- hr = HRESULT_FROM_WIN32(ret);
- HeapFree(GetProcessHeap(), 0, pszFileType);
+ hr = ASSOC_ReturnString(flags, pszOut, pcchOut, docName, strlenW(docName) + 1);
return hr;
}
@@ -623,41 +602,28 @@ get_friendly_name_fail:
case ASSOCSTR_DEFAULTICON:
{
static const WCHAR DefaultIconW[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
- WCHAR *pszFileType;
DWORD ret;
DWORD size;
- HKEY hkeyFile;
- hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
- if (FAILED(hr))
- return hr;
- ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
+ size = 0;
+ ret = RegGetValueW(This->hkeyProgID, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
if (ret == ERROR_SUCCESS)
{
- size = 0;
- ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
- if (ret == ERROR_SUCCESS)
+ WCHAR *icon = HeapAlloc(GetProcessHeap(), 0, size);
+ if (icon)
{
- WCHAR *icon = HeapAlloc(GetProcessHeap(), 0, size);
- if (icon)
- {
- ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
- if (ret == ERROR_SUCCESS)
- hr = ASSOC_ReturnString(flags, pszOut, pcchOut, icon, strlenW(icon) + 1);
- else
- hr = HRESULT_FROM_WIN32(ret);
- HeapFree(GetProcessHeap(), 0, icon);
- }
+ ret = RegGetValueW(This->hkeyProgID, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
+ if (ret == ERROR_SUCCESS)
+ hr = ASSOC_ReturnString(flags, pszOut, pcchOut, icon, strlenW(icon) + 1);
else
- hr = E_OUTOFMEMORY;
+ hr = HRESULT_FROM_WIN32(ret);
+ HeapFree(GetProcessHeap(), 0, icon);
}
else
- hr = HRESULT_FROM_WIN32(ret);
- RegCloseKey(hkeyFile);
+ hr = E_OUTOFMEMORY;
}
else
hr = HRESULT_FROM_WIN32(ret);
- HeapFree(GetProcessHeap(), 0, pszFileType);
return hr;
}
case ASSOCSTR_SHELLEXTENSION:
diff --git a/dlls/shell32/tests/assoc.c b/dlls/shell32/tests/assoc.c
index 8aa2535..126a372 100644
--- a/dlls/shell32/tests/assoc.c
+++ b/dlls/shell32/tests/assoc.c
@@ -91,12 +91,14 @@ struct assoc_getstring_test
};
static const WCHAR httpW[] = {'h','t','t','p',0};
+static const WCHAR InternetShortcutW[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0};
static const WCHAR badW[] = {'b','a','d','b','a','d',0};
static struct assoc_getstring_test getstring_tests[] =
{
{ httpW, 0, ASSOCSTR_EXECUTABLE, 2, 0x8007007a /* E_NOT_SUFFICIENT_BUFFER */, S_OK },
{ httpW, ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, 2, E_POINTER },
+ { InternetShortcutW, 0, ASSOCSTR_DEFAULTICON, 10, S_OK, 0x80070002 /* HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) */},
{ NULL }
};
@@ -135,7 +137,7 @@ static void test_IQueryAssociations_GetString(void)
else
{
ok(hr == ptr->hr, "%d: GetString failed, 0x%08x\n", i, hr);
- ok(len > ptr->len, "%d: got needed length %d\n", i, len);
+ ok(len >= ptr->len, "%d: got needed length %d\n", i, len);
}
/* even with ASSOCF_NOTRUNCATE it's null terminated */
--
2.5.4 (Apple Git-61)
More information about the wine-patches
mailing list