shell32: fix folder icon index when read from registry

Martin Fuchs martin-fuchs at gmx.net
Mon Jan 9 03:03:24 CST 2006


> >> Any reason you using int* instead of LPINT?
> > 
> > What's better when using LPINT? This are all internal functions and
> > not exported from shell32.dll.

> 'INT' has the same size on all platforms and with all compilers in both
> win32 and win64, while 'int' is platform/compiler dependent and is 32-bit
> or 64-bit entity depending on the platform.

Who cares in this case?

Alexandre, take whatever version of the patch you want...

Changelog:
- fix folder icon index when read from registry
- change "DWORD dwNr" into "int icon_idx" at several places


Index: dlls/shell32/shell32_main.h
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shell32_main.h,v
retrieving revision 1.110
diff -u -p -d -r1.110 shell32_main.h
--- shell32_main.h	28 Nov 2005 11:04:35 -0000	1.110
+++ shell32_main.h	7 Jan 2006 16:19:07 -0000
@@ -58,13 +58,13 @@ INT SIC_GetIconIndex (LPCWSTR sSourceFil
 /* Classes Root */
 BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, LONG len, BOOL bPrependDot);
 BOOL HCR_GetExecuteCommandW( HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len );
-BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr);
-BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr);
+BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPINT picon_idx);
+BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPINT picon_idx);
 BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len);
 
 /* ANSI versions of above functions, supposed to go away as soon as they are not used anymore */
 BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, LONG len, BOOL bPrependDot);
-BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr);
+BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPINT picon_idx);
 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len);
 
 BOOL HCR_GetFolderAttributes(LPCITEMIDLIST pidlFolder, LPDWORD dwAttributes);
Index: dlls/shell32/folders.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/folders.c,v
retrieving revision 1.66
diff -u -p -d -r1.66 folders.c
--- folders.c	26 Aug 2005 10:05:35 -0000	1.66
+++ folders.c	7 Jan 2006 16:18:42 -0000
@@ -166,7 +166,7 @@ static HRESULT getIconLocationForFolder(
  LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
 {
     IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
-    DWORD dwNr;
+    INT icon_idx;
     WCHAR wszPath[MAX_PATH];
     WCHAR wszCLSIDValue[CHARS_IN_GUID];
     static const WCHAR shellClassInfo[] = { '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
@@ -185,27 +185,32 @@ static HRESULT getIconLocationForFolder(
     }
     else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid,
         wszCLSIDValue, CHARS_IN_GUID) &&
-        HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
+        HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &icon_idx))
     {
-       *piIndex = dwNr;
+       *piIndex = icon_idx;
     }
     else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid2,
         wszCLSIDValue, CHARS_IN_GUID) &&
-        HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
+        HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &icon_idx))
     {
-       *piIndex = dwNr;
+       *piIndex = icon_idx;
     }
     else
     {
         static const WCHAR folder[] = { 'F','o','l','d','e','r',0 };
 
-        if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &dwNr))
+        if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &icon_idx))
         {
             lstrcpynW(szIconFile, swShell32Name, cchMax);
-            dwNr = IDI_SHELL_FOLDER;
+            icon_idx = -IDI_SHELL_FOLDER;
         }
-        *piIndex = -((uFlags & GIL_OPENICON) ? dwNr + 1 : dwNr);
+
+        if (uFlags & GIL_OPENICON)
+            *piIndex = icon_idx<0? icon_idx-1: icon_idx+1;
+        else
+            *piIndex = icon_idx;
     }
+
     return S_OK;
 }
 
@@ -227,7 +232,7 @@ static HRESULT WINAPI IExtractIconW_fnGe
 	IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
 
 	char	sTemp[MAX_PATH];
-	DWORD	dwNr;
+	INT		icon_idx;
 	GUID const * riid;
 	LPITEMIDLIST	pSimplePidl = ILFindLastID(This->pidl);
 
@@ -256,9 +261,9 @@ static HRESULT WINAPI IExtractIconW_fnGe
 	          riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
 	          riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
 
-	  if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &dwNr))
+	  if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &icon_idx))
 	  {
-	    *piIndex = dwNr;
+	    *piIndex = icon_idx;
 	  }
 	  else
 	  {
@@ -301,9 +306,9 @@ static HRESULT WINAPI IExtractIconW_fnGe
 	  }
 	  else
 	  {
-		if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &dwNr))
+		if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &icon_idx))
 		{
-		  *piIndex = dwNr;
+		  *piIndex = icon_idx;
 		}
 		else
 		{
@@ -329,7 +334,7 @@ static HRESULT WINAPI IExtractIconW_fnGe
 	  else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
 	  {
 	    if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
-		&& HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
+		&& HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &icon_idx))
 	    {
 	      if (!lstrcmpA("%1", sTemp))		/* icon is in the file */
 	      {
@@ -339,7 +344,7 @@ static HRESULT WINAPI IExtractIconW_fnGe
 	      else
 	      {
 		MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
-		*piIndex = dwNr;
+		*piIndex = icon_idx;
 	      }
 
 	      found = TRUE;
Index: dlls/shell32/iconcache.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/iconcache.c,v
retrieving revision 1.97
diff -u -p -d -r1.97 iconcache.c
--- iconcache.c	28 Nov 2005 11:02:32 -0000	1.97
+++ iconcache.c	7 Jan 2006 16:18:42 -0000
@@ -97,7 +97,7 @@ static INT CALLBACK SIC_CompareEntries( 
 }
 
 /* declare SIC_LoadOverlayIcon() */
-static int SIC_LoadOverlayIcon(int idx);
+static int SIC_LoadOverlayIcon(INT icon_idx);
 
 /*****************************************************************************
  * SIC_OverlayShortcutImage			[internal]
@@ -467,7 +467,7 @@ void SIC_Destroy(void)
  *
  * Load a shell overlay icon and return its icon cache index.
  */
-static int SIC_LoadOverlayIcon(int idx)
+static int SIC_LoadOverlayIcon(INT icon_idx)
 {
 	WCHAR buffer[1024], wszIdx[8];
 	HKEY hKeyShellIcons;
@@ -482,13 +482,13 @@ static int SIC_LoadOverlayIcon(int idx)
 	static const WCHAR wszNumFmt[] = {'%','d',0};
 
 	iconPath = swShell32Name;	/* default: load icon from shell32.dll */
-	iconIdx = idx;
+	iconIdx = icon_idx;
 
 	if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszShellIcons, 0, KEY_READ, &hKeyShellIcons) == ERROR_SUCCESS)
 	{
 	    DWORD count = sizeof(buffer);
 
-	    sprintfW(wszIdx, wszNumFmt, idx);
+	    sprintfW(wszIdx, wszNumFmt, icon_idx);
 
 	    /* read icon path and index */
 	    if (RegQueryValueExW(hKeyShellIcons, wszIdx, NULL, NULL, (LPBYTE)buffer, &count) == ERROR_SUCCESS)
Index: dlls/shell32/shell32_main.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shell32_main.c,v
retrieving revision 1.157
diff -u -p -d -r1.157 shell32_main.c
--- shell32_main.c	21 Nov 2005 13:35:06 -0000	1.157
+++ shell32_main.c	7 Jan 2006 16:11:45 -0000
@@ -536,7 +536,7 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR 
         {
             WCHAR sTemp [MAX_PATH];
             WCHAR * szExt;
-            DWORD dwNr=0;
+            DWORD icon_idx=0;
 
             lstrcpynW(sTemp, szFullPath, MAX_PATH);
 
@@ -550,14 +550,14 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR 
                 szExt = (LPWSTR) PathFindExtensionW(sTemp);
                 if ( szExt &&
                      HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
-                     HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &dwNr))
+                     HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
                 {
                     if (!lstrcmpW(p1W,sTemp))            /* icon is in the file */
                         strcpyW(sTemp, szFullPath);
 
                     if (flags & SHGFI_SYSICONINDEX) 
                     {
-                        psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr,0);
+                        psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
                         if (psfi->iIcon == -1)
                             psfi->iIcon = 0;
                     }
@@ -565,16 +565,16 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR 
                     {
                         IconNotYetLoaded=FALSE;
                         if (flags & SHGFI_SMALLICON)
-                            PrivateExtractIconsW( sTemp,dwNr,
+                            PrivateExtractIconsW( sTemp,icon_idx,
                                 GetSystemMetrics( SM_CXSMICON ),
                                 GetSystemMetrics( SM_CYSMICON ),
                                 &psfi->hIcon, 0, 1, 0);
                         else
-                            PrivateExtractIconsW( sTemp, dwNr,
+                            PrivateExtractIconsW( sTemp, icon_idx,
                                 GetSystemMetrics( SM_CXICON),
                                 GetSystemMetrics( SM_CYICON),
                                 &psfi->hIcon, 0, 1, 0);
-                        psfi->iIcon = dwNr;
+                        psfi->iIcon = icon_idx;
                     }
                 }
             }
Index: dlls/shell32/classes.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/classes.c,v
retrieving revision 1.42
diff -u -p -d -r1.42 classes.c
--- classes.c	18 Jul 2005 13:13:05 -0000	1.42
+++ classes.c	7 Jan 2006 16:19:07 -0000
@@ -164,31 +164,31 @@ static BOOL HCR_RegOpenClassIDKey(REFIID
 	return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
 }
 
-static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPDWORD dwNr)
+static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPINT picon_idx)
 {
-	DWORD dwType;
-	WCHAR sTemp[MAX_PATH];
-	WCHAR sNum[5];
+    DWORD dwType;
+    WCHAR sTemp[MAX_PATH];
+    WCHAR sNum[5];
 
-	if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
-	{
+    if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
+    {
       if (dwType == REG_EXPAND_SZ)
-	  {
-	    ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
-	    lstrcpynW(szDest, sTemp, len);
-	  }
-	  if (ParseFieldW (szDest, 2, sNum, 5))
-             *dwNr = atoiW(sNum);
+      {
+        ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
+        lstrcpynW(szDest, sTemp, len);
+      }
+      if (ParseFieldW (szDest, 2, sNum, 5))
+             *picon_idx = atoiW(sNum);
           else
-             *dwNr=0; /* sometimes the icon number is missing */
-	  ParseFieldW (szDest, 1, szDest, len);
+             *picon_idx=0; /* sometimes the icon number is missing */
+      ParseFieldW (szDest, 1, szDest, len);
           PathUnquoteSpacesW(szDest);
-	  return TRUE;
-	}
-	return FALSE;
+      return TRUE;
+    }
+    return FALSE;
 }
 
-static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPDWORD dwNr)
+static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPINT picon_idx)
 {
 	DWORD dwType;
 	char sTemp[MAX_PATH];
@@ -202,9 +202,9 @@ static BOOL HCR_RegGetDefaultIconA(HKEY 
 	    lstrcpynA(szDest, sTemp, len);
 	  }
 	  if (ParseFieldA (szDest, 2, sNum, 5))
-             *dwNr=atoi(sNum);
+             *picon_idx=atoi(sNum);
           else
-             *dwNr=0; /* sometimes the icon number is missing */
+             *picon_idx=0; /* sometimes the icon number is missing */
 	  ParseFieldA (szDest, 1, szDest, len);
           PathUnquoteSpacesA(szDest);
 	  return TRUE;
@@ -212,7 +212,7 @@ static BOOL HCR_RegGetDefaultIconA(HKEY 
 	return FALSE;
 }
 
-BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr)
+BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPINT picon_idx)
 {
         static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
 	HKEY	hkey;
@@ -226,19 +226,19 @@ BOOL HCR_GetDefaultIconW(LPCWSTR szClass
 
 	if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
 	{
-	  ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
+	  ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx);
 	  RegCloseKey(hkey);
 	}
 
         if(ret)
-            TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
+            TRACE("-- %s %li\n", debugstr_w(szDest), *picon_idx);
         else
             TRACE("-- not found\n");
 
 	return ret;
 }
 
-BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
+BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPINT picon_idx)
 {
 	HKEY	hkey;
 	char	sTemp[MAX_PATH];
@@ -250,24 +250,24 @@ BOOL HCR_GetDefaultIconA(LPCSTR szClass,
 
 	if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
 	{
-	  ret = HCR_RegGetDefaultIconA(hkey, szDest, len, dwNr);
+	  ret = HCR_RegGetDefaultIconA(hkey, szDest, len, picon_idx);
 	  RegCloseKey(hkey);
 	}
-	TRACE("-- %s %li\n", szDest, *dwNr );
+	TRACE("-- %s %li\n", szDest, *picon_idx);
 	return ret;
 }
 
-BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr)
+BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPINT picon_idx)
 {
 	HKEY	hkey;
 	BOOL	ret = FALSE;
 
 	if (HCR_RegOpenClassIDKey(riid, &hkey))
 	{
-	  ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
+	  ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx);
 	  RegCloseKey(hkey);
 	}
-	TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
+	TRACE("-- %s %li\n", debugstr_w(szDest), *picon_idx);
 	return ret;
 }
 




More information about the wine-patches mailing list