shell32 patch 33

Martin Fuchs martin-fuchs at gmx.net
Fri Apr 9 07:24:53 CDT 2004


Changelog:
- eliminate MSVC type conversion warning
- IShellLink::GetIconLocation(): get icons for shell links if not already set


Index: shelllink.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shelllink.c,v
retrieving revision 1.66
diff -u -p -d -r1.66 shelllink.c
--- shelllink.c	7 Apr 2004 03:59:41 -0000	1.66
+++ shelllink.c	9 Apr 2004 12:23:11 -0000
@@ -546,7 +546,7 @@ static HRESULT WINAPI IPersistStream_fnL
         if( FAILED( r ) )
             return r;
     }
-    This->wHotKey = hdr.wHotKey;
+    This->wHotKey = (WORD)hdr.wHotKey;
     This->iIcoNdx = hdr.nIcon;
     FileTimeToSystemTime (&hdr.Time1, &This->time1);
     FileTimeToSystemTime (&hdr.Time2, &This->time2);
@@ -1195,20 +1195,75 @@ static HRESULT WINAPI IShellLinkA_fnSetS
     return NOERROR;
 }
 
+static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPITEMIDLIST 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, (LPCITEMIDLIST*)&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)
 {
     ICOM_THIS(IShellLinkImpl, iface);
 
     TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
 
-    if( cchIconPath )
+    if (cchIconPath)
         pszIconPath[0] = 0;
-    if( This->sIcoPath )
-        WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
-                             pszIconPath, cchIconPath, NULL, NULL);
-    *piIcon = This->iIcoNdx;
 
-    return NOERROR;
+    if (This->sIcoPath) {
+        WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
+	*piIcon = This->iIcoNdx;
+	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);
+	}
+
+	return hr;
+    } else
+        return E_FAIL;
 }
 
 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
@@ -1519,19 +1574,75 @@ static HRESULT WINAPI IShellLinkW_fnSetS
     return S_OK;
 }
 
+static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPITEMIDLIST 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, (LPCITEMIDLIST*)&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)
 {
     _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
 
     TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
 
-    if( cchIconPath )
+    if (cchIconPath)
         pszIconPath[0] = 0;
-    if( This->sIcoPath )
-        lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
-    *piIcon = This->iIcoNdx;
 
-    return S_OK;
+    if (This->sIcoPath) {
+	lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
+	*piIcon = This->iIcoNdx;
+	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);
+		}
+	    }
+
+	    IShellFolder_Release(pdsk);
+	}
+
+	return hr;
+    } else
+        return E_FAIL;
 }
 
 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)





More information about the wine-patches mailing list