Andrew Eikum : shell32: Don't search Path or PIDL for an icon in IShellLink ::GetIconLocation.
Alexandre Julliard
julliard at winehq.org
Fri Nov 12 11:22:33 CST 2010
Module: wine
Branch: master
Commit: d66317605d2744a409db65170490243e1fffbf8b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d66317605d2744a409db65170490243e1fffbf8b
Author: Andrew Eikum <aeikum at codeweavers.com>
Date: Thu Nov 11 15:58:37 2010 -0600
shell32: Don't search Path or PIDL for an icon in IShellLink::GetIconLocation.
Try as I might, I couldn't get a path out of GetIconLocation that wasn't
put there via SetIconLocation. As far as I can tell, the code here was
based on nothing.
---
dlls/shell32/shelllink.c | 126 +--------------------------------------
dlls/shell32/tests/shelllink.c | 64 ++++++++++++++++++++-
2 files changed, 66 insertions(+), 124 deletions(-)
diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c
index a052a18..b4a977a 100644
--- a/dlls/shell32/shelllink.c
+++ b/dlls/shell32/shelllink.c
@@ -1593,78 +1593,19 @@ static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd
return NOERROR;
}
-static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPCITEMIDLIST pidl,
- LPSTR pszIconPath, int cchIconPath, int* piIcon)
-{
- LPCITEMIDLIST pidlLast;
-
- HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
-
- if (SUCCEEDED(hr)) {
- IExtractIconA* pei;
-
- hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
-
- if (SUCCEEDED(hr)) {
- hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
-
- IExtractIconA_Release(pei);
- }
-
- IShellFolder_Release(psf);
- }
-
- return hr;
-}
-
static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
{
IShellLinkImpl *This = (IShellLinkImpl *)iface;
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
- pszIconPath[0] = 0;
*piIcon = This->iIcoNdx;
if (This->sIcoPath)
- {
WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
- return S_OK;
- }
-
- if (This->pPidl || This->sPath)
- {
- IShellFolder* pdsk;
-
- HRESULT hr = SHGetDesktopFolder(&pdsk);
-
- if (SUCCEEDED(hr))
- {
- /* first look for an icon using the PIDL (if present) */
- if (This->pPidl)
- hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
- else
- hr = E_FAIL;
-
- /* if we couldn't find an icon yet, look for it using the file system path */
- if (FAILED(hr) && This->sPath)
- {
- LPITEMIDLIST pidl;
-
- hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
-
- if (SUCCEEDED(hr)) {
- hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
-
- SHFree(pidl);
- }
- }
-
- IShellFolder_Release(pdsk);
- }
+ else
+ pszIconPath[0] = 0;
- return hr;
- }
return S_OK;
}
@@ -1984,78 +1925,19 @@ static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd
return S_OK;
}
-static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPCITEMIDLIST pidl,
- LPWSTR pszIconPath, int cchIconPath, int* piIcon)
-{
- LPCITEMIDLIST pidlLast;
-
- HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
-
- if (SUCCEEDED(hr)) {
- IExtractIconW* pei;
-
- hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
-
- if (SUCCEEDED(hr)) {
- hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
-
- IExtractIconW_Release(pei);
- }
-
- IShellFolder_Release(psf);
- }
-
- return hr;
-}
-
static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
{
IShellLinkImpl *This = impl_from_IShellLinkW(iface);
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
- pszIconPath[0] = 0;
*piIcon = This->iIcoNdx;
if (This->sIcoPath)
- {
lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
- return S_OK;
- }
-
- if (This->pPidl || This->sPath)
- {
- IShellFolder* pdsk;
-
- HRESULT hr = SHGetDesktopFolder(&pdsk);
-
- if (SUCCEEDED(hr))
- {
- /* first look for an icon using the PIDL (if present) */
- if (This->pPidl)
- hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
- else
- hr = E_FAIL;
-
- /* if we couldn't find an icon yet, look for it using the file system path */
- if (FAILED(hr) && This->sPath)
- {
- LPITEMIDLIST pidl;
-
- hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
-
- if (SUCCEEDED(hr))
- {
- hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
-
- SHFree(pidl);
- }
- }
+ else
+ pszIconPath[0] = 0;
- IShellFolder_Release(pdsk);
- }
- return hr;
- }
return S_OK;
}
diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c
index 55ba936..2277e5e 100644
--- a/dlls/shell32/tests/shelllink.c
+++ b/dlls/shell32/tests/shelllink.c
@@ -325,8 +325,8 @@ static void test_get_set(void)
strcpy(buffer,"garbage");
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
- todo_wine ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
- todo_wine ok(i==0, "GetIconLocation returned %d\n", i);
+ ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
+ ok(i==0, "GetIconLocation returned %d\n", i);
str="c:\\nonexistent\\file";
r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
@@ -868,6 +868,65 @@ static void test_shdefextracticon(void)
ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
}
+static void test_GetIconLocation(void)
+{
+ IShellLinkA *sl;
+ const char *str;
+ char buffer[INFOTIPSIZE], mypath[MAX_PATH];
+ int i;
+ HRESULT r;
+ LPITEMIDLIST pidl;
+
+ r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IShellLinkA, (LPVOID*)&sl);
+ ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
+ if(r != S_OK)
+ return;
+
+ i = 0xdeadbeef;
+ strcpy(buffer, "garbage");
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0, "GetIconLocation returned %d\n", i);
+
+ str = "c:\\some\\path";
+ r = IShellLinkA_SetPath(sl, str);
+ ok(r == S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
+
+ i = 0xdeadbeef;
+ strcpy(buffer, "garbage");
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0, "GetIconLocation returned %d\n", i);
+
+ GetWindowsDirectoryA(mypath, sizeof(mypath) - 12);
+ strcat(mypath, "\\regedit.exe");
+ pidl = path_to_pidl(mypath);
+ r = IShellLinkA_SetIDList(sl, pidl);
+ ok(r == S_OK, "SetPath failed (0x%08x)\n", r);
+
+ i = 0xdeadbeef;
+ strcpy(buffer, "garbage");
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0, "GetIconLocation returned %d\n", i);
+
+ str = "c:\\nonexistent\\file";
+ r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
+ ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
+
+ i = 0xdeadbeef;
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(lstrcmpi(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
+
+ IShellLinkA_Release(sl);
+}
+
START_TEST(shelllink)
{
HRESULT r;
@@ -891,6 +950,7 @@ START_TEST(shelllink)
test_load_save();
test_datalink();
test_shdefextracticon();
+ test_GetIconLocation();
CoUninitialize();
}
More information about the wine-cvs
mailing list