Recovery of release 990110 after disk crash.
[wine.git] / dlls / shell32 / iconcache.c
blobaad6a79f46c02f4ec8b472502d91b7c91cf88345
1 /*
2 * shell icon cache (SIC)
5 */
6 #include <string.h>
7 #include "windows.h"
8 #include "wine/winuser16.h"
9 #include "neexe.h"
10 #include "cursoricon.h"
11 #include "module.h"
12 #include "heap.h"
13 #include "debug.h"
14 #include "sysmetrics.h"
15 #include "winversion.h"
16 #include "shell.h"
17 #include "shlobj.h"
18 #include "pidl.h"
19 #include "shell32_main.h"
21 #pragma pack(1)
23 typedef struct
25 BYTE bWidth; /* Width, in pixels, of the image */
26 BYTE bHeight; /* Height, in pixels, of the image */
27 BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
28 BYTE bReserved; /* Reserved ( must be 0) */
29 WORD wPlanes; /* Color Planes */
30 WORD wBitCount; /* Bits per pixel */
31 DWORD dwBytesInRes; /* How many bytes in this resource? */
32 DWORD dwImageOffset; /* Where in the file is this image? */
33 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
35 typedef struct
37 WORD idReserved; /* Reserved (must be 0) */
38 WORD idType; /* Resource Type (1 for icons) */
39 WORD idCount; /* How many images? */
40 icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
41 } icoICONDIR, *LPicoICONDIR;
43 #pragma pack(4)
45 /*************************************************************************
46 * SHELL_GetResourceTable
48 static DWORD SHELL_GetResourceTable(HFILE32 hFile,LPBYTE *retptr)
49 { IMAGE_DOS_HEADER mz_header;
50 char magic[4];
51 int size;
53 TRACE(shell,"\n");
55 *retptr = NULL;
56 _llseek32( hFile, 0, SEEK_SET );
57 if ((_lread32(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
58 { if (mz_header.e_cblp == 1) /* .ICO file ? */
59 { *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
60 return 1;
62 else
63 return 0; /* failed */
65 _llseek32( hFile, mz_header.e_lfanew, SEEK_SET );
67 if (_lread32( hFile, magic, sizeof(magic) ) != sizeof(magic))
68 return 0;
70 _llseek32( hFile, mz_header.e_lfanew, SEEK_SET);
72 if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
73 return IMAGE_NT_SIGNATURE;
75 if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
76 { IMAGE_OS2_HEADER ne_header;
77 LPBYTE pTypeInfo = (LPBYTE)-1;
79 if (_lread32(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
80 return 0;
82 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
83 return 0;
85 size = ne_header.rname_tab_offset - ne_header.resource_tab_offset;
87 if( size > sizeof(NE_TYPEINFO) )
88 { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
89 if( pTypeInfo )
90 { _llseek32(hFile, mz_header.e_lfanew+ne_header.resource_tab_offset, SEEK_SET);
91 if( _lread32( hFile, (char*)pTypeInfo, size) != size )
92 { HeapFree( GetProcessHeap(), 0, pTypeInfo);
93 pTypeInfo = NULL;
97 *retptr = pTypeInfo;
98 return IMAGE_OS2_SIGNATURE;
100 return 0; /* failed */
102 /*************************************************************************
103 * SHELL_LoadResource
105 static HGLOBAL16 SHELL_LoadResource(HINSTANCE32 hInst, HFILE32 hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)
106 { BYTE* ptr;
107 HGLOBAL16 handle = DirectResAlloc( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);
109 TRACE(shell,"\n");
111 if( (ptr = (BYTE*)GlobalLock16( handle )) )
112 { _llseek32( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
113 _lread32( hFile, (char*)ptr, pNInfo->length << sizeShift);
114 return handle;
116 return 0;
119 /*************************************************************************
120 * ICO_LoadIcon
122 static HGLOBAL16 ICO_LoadIcon(HINSTANCE32 hInst, HFILE32 hFile, LPicoICONDIRENTRY lpiIDE)
123 { BYTE* ptr;
124 HGLOBAL16 handle = DirectResAlloc( hInst, 0x10, lpiIDE->dwBytesInRes);
125 TRACE(shell,"\n");
126 if( (ptr = (BYTE*)GlobalLock16( handle )) )
127 { _llseek32( hFile, lpiIDE->dwImageOffset, SEEK_SET);
128 _lread32( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
129 return handle;
131 return 0;
134 /*************************************************************************
135 * ICO_GetIconDirectory
137 * Read .ico file and build phony ICONDIR struct for GetIconID
139 static HGLOBAL16 ICO_GetIconDirectory(HINSTANCE32 hInst, HFILE32 hFile, LPicoICONDIR* lplpiID )
140 { WORD id[3]; /* idReserved, idType, idCount */
141 LPicoICONDIR lpiID;
142 int i;
144 TRACE(shell,"\n");
145 _llseek32( hFile, 0, SEEK_SET );
146 if( _lread32(hFile,(char*)id,sizeof(id)) != sizeof(id) )
147 return 0;
149 /* check .ICO header
151 * - see http://www.microsoft.com/win32dev/ui/icons.htm
154 if( id[0] || id[1] != 1 || !id[2] )
155 return 0;
157 i = id[2]*sizeof(icoICONDIRENTRY) + sizeof(id);
159 lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i);
161 if( _lread32(hFile,(char*)lpiID->idEntries,i) == i )
162 { HGLOBAL16 handle = DirectResAlloc( hInst, 0x10,id[2]*sizeof(ICONDIRENTRY) + sizeof(id) );
163 if( handle )
164 { CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock16( handle );
165 lpID->idReserved = lpiID->idReserved = id[0];
166 lpID->idType = lpiID->idType = id[1];
167 lpID->idCount = lpiID->idCount = id[2];
168 for( i=0; i < lpiID->idCount; i++ )
169 { memcpy((void*)(lpID->idEntries + i),(void*)(lpiID->idEntries + i), sizeof(ICONDIRENTRY) - 2);
170 lpID->idEntries[i].icon.wResId = i;
172 *lplpiID = lpiID;
173 return handle;
176 /* fail */
178 HeapFree( GetProcessHeap(), 0, lpiID);
179 return 0;
182 /*************************************************************************
183 * InternalExtractIcon [SHELL.39]
185 * This abortion is called directly by Progman
186 * fixme: the icon section is broken (don't have a handle for
187 * ICO_GetIconDirectory....)
190 #define ICO_INVALID_FILE 1
191 #define ICO_NO_ICONS 0
193 HGLOBAL32 WINAPI ICO_ExtractIconEx(LPCSTR lpszExeFileName, HICON32* RetPtr, UINT32 nIconIndex, UINT32 n, UINT32 cxDesired, UINT32 cyDesired )
194 { HGLOBAL32 hRet = ICO_NO_ICONS;
195 LPBYTE pData;
196 OFSTRUCT ofs;
197 DWORD sig;
198 HFILE32 hFile = OpenFile32( lpszExeFileName, &ofs, OF_READ );
199 UINT16 iconDirCount = 0,iconCount = 0;
200 LPBYTE peimage;
201 HANDLE32 fmapping;
203 TRACE(shell,"(file %s,start %d,extract %d\n", lpszExeFileName, nIconIndex, n);
205 if( hFile == HFILE_ERROR32 || !n )
206 return ICO_INVALID_FILE;
208 sig = SHELL_GetResourceTable(hFile,&pData);
210 /* ico file */
211 if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
212 { HICON16 hIcon = 0;
213 NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);
214 NE_NAMEINFO* pIconStorage = NULL;
215 NE_NAMEINFO* pIconDir = NULL;
216 LPicoICONDIR lpiID = NULL;
218 if( pData == (BYTE*)-1 )
219 { hIcon = ICO_GetIconDirectory(0, hFile, &lpiID); /* check for .ICO file */
220 if( hIcon )
221 { iconDirCount = 1; iconCount = lpiID->idCount;
224 else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
225 { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
226 { iconDirCount = pTInfo->count;
227 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
228 TRACE(shell,"\tfound directory - %i icon families\n", iconDirCount);
230 if( pTInfo->type_id == NE_RSCTYPE_ICON )
231 { iconCount = pTInfo->count;
232 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
233 TRACE(shell,"\ttotal icons - %i\n", iconCount);
235 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
238 if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
239 { if( nIconIndex == (UINT16)-1 )
240 { RetPtr[0] = iconDirCount;
242 else if( nIconIndex < iconDirCount )
243 { UINT16 i, icon;
244 if( n > iconDirCount - nIconIndex )
245 n = iconDirCount - nIconIndex;
247 for( i = nIconIndex; i < nIconIndex + n; i++ )
248 { /* .ICO files have only one icon directory */
250 if( lpiID == NULL )
251 hIcon = SHELL_LoadResource( 0, hFile, pIconDir + i, *(WORD*)pData );
252 RetPtr[i-nIconIndex] = GetIconID( hIcon, 3 );
253 GlobalFree16(hIcon);
256 for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
257 { hIcon = 0;
258 if( lpiID )
259 { hIcon = ICO_LoadIcon( 0, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);
261 else
262 { for( i = 0; i < iconCount; i++ )
263 { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
264 { hIcon = SHELL_LoadResource( 0, hFile, pIconStorage + i,*(WORD*)pData );
268 if( hIcon )
269 { RetPtr[icon-nIconIndex] = LoadIconHandler( hIcon, TRUE );
271 else
272 { RetPtr[icon-nIconIndex] = 0;
277 if( lpiID )
278 HeapFree( GetProcessHeap(), 0, lpiID);
279 else
280 HeapFree( GetProcessHeap(), 0, pData);
282 /* end ico file */
284 /* exe/dll */
285 if( sig == IMAGE_NT_SIGNATURE)
286 { LPBYTE idata,igdata;
287 PIMAGE_DOS_HEADER dheader;
288 PIMAGE_NT_HEADERS pe_header;
289 PIMAGE_SECTION_HEADER pe_sections;
290 PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
291 PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
292 PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
293 int i,j;
295 if ( !(fmapping = CreateFileMapping32A(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
296 { WARN(shell,"failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
297 hRet = ICO_INVALID_FILE;
298 goto end_2; /* failure */
301 if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
302 { WARN(shell,"failed to mmap filemap.\n");
303 hRet = ICO_INVALID_FILE;
304 goto end_2; /* failure */
307 dheader = (PIMAGE_DOS_HEADER)peimage;
308 pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, SHELL_GetResourceTable checked that */
309 pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
310 rootresdir = NULL;
312 for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
313 { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
314 continue;
315 /* FIXME: doesn't work when the resources are not in a seperate section */
316 if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
317 { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
318 break;
322 if (!rootresdir)
323 { WARN(shell,"haven't found section for resource directory.\n");
324 goto end_4; /* failure */
326 /* search the group icon dir*/
327 if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICON32W, (DWORD)rootresdir,FALSE)))
328 { WARN(shell,"No Icongroupresourcedirectory!\n");
329 goto end_4; /* failure */
331 iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
333 /* number of icons requested */
334 if( nIconIndex == -1 )
335 { hRet = iconDirCount;
336 goto end_3; /* success */
339 if (nIconIndex >= iconDirCount)
340 { WARN(shell,"nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
341 goto end_4; /* failure */
344 xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); /* caller just wanted the number of entries */
346 if( n > iconDirCount - nIconIndex ) /* assure we don't get too much ... */
347 { n = iconDirCount - nIconIndex;
350 xresent = xresent+nIconIndex; /* starting from specified index ... */
352 for (i=0;i<n;i++,xresent++)
353 { PIMAGE_RESOURCE_DIRECTORY resdir;
355 /* go down this resource entry, name */
356 resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
358 /* default language (0) */
359 resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
360 igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
362 /* lookup address in mapped image for virtual address */
363 igdata = NULL;
365 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
366 { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
367 continue;
368 if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
369 continue;
370 igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
373 if (!igdata)
374 { WARN(shell,"no matching real address for icongroup!\n");
375 goto end_4; /* failure */
377 RetPtr[i] = LookupIconIdFromDirectoryEx32(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
380 if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICON32W,(DWORD)rootresdir,FALSE)))
381 { WARN(shell,"No Iconresourcedirectory!\n");
382 goto end_4; /* failure */
385 for (i=0;i<n;i++)
386 { PIMAGE_RESOURCE_DIRECTORY xresdir;
387 xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
388 xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
389 idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
390 idata = NULL;
392 /* map virtual to address in image */
393 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
394 { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
395 continue;
396 if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
397 continue;
398 idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
400 if (!idata)
401 { WARN(shell,"no matching real address found for icondata!\n");
402 RetPtr[i]=0;
403 continue;
405 RetPtr[i] = CreateIconFromResourceEx32(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
407 hRet = RetPtr[0]; /* return first icon */
408 goto end_3; /* sucess */
410 hRet = ICO_INVALID_FILE;
411 goto end_1; /* unknown filetype */
413 /* cleaning up (try & catch would be nicer:-) ) */
414 end_4: hRet = 0; /* failure */
415 end_3: UnmapViewOfFile(peimage); /* success */
416 end_2: CloseHandle(fmapping);
417 end_1: _lclose32( hFile);
418 return hRet;
421 /********************** THE ICON CACHE ********************************/
422 HIMAGELIST ShellSmallIconList = 0;
423 HIMAGELIST ShellBigIconList = 0;
424 HDPA hdpa=0;
426 #define INVALID_INDEX -1
428 typedef struct
429 { LPCSTR sSourceFile; /* file icon is from */
430 DWORD dwSourceIndex; /* index within the file */
431 DWORD dwListIndex; /* index within the iconlist */
432 } SIC_ENTRY, * LPSIC_ENTRY;
434 /*****************************************************************************
435 * SIC_CompareEntrys [called by comctl32.dll]
436 * NOTES
437 * Callback for DPA_Search
439 INT32 CALLBACK SIC_CompareEntrys( LPVOID p1, LPVOID p2, LPARAM lparam)
440 { TRACE(shell,"%p %p\n", p1, p2);
442 if (((LPSIC_ENTRY)p1)->dwSourceIndex != ((LPSIC_ENTRY)p2)->dwSourceIndex) /* first the faster one*/
443 return 1;
445 if (strcasecmp(((LPSIC_ENTRY)p1)->sSourceFile,((LPSIC_ENTRY)p2)->sSourceFile))
446 return 1;
448 return 0;
450 /*****************************************************************************
451 * SIC_IconAppend (internal)
452 * NOTES
453 * appends a icon pair to the end of the cache
455 static INT32 SIC_IconAppend (LPCSTR sSourceFile, INT32 dwSourceIndex, HICON32 hSmallIcon, HICON32 hBigIcon)
456 { LPSIC_ENTRY lpsice;
457 INT32 index, index1;
459 TRACE(shell,"%s %i %x %x\n", sSourceFile, dwSourceIndex, hSmallIcon ,hBigIcon);
461 lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));
463 lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(),0,sSourceFile);
464 lpsice->dwSourceIndex = dwSourceIndex;
466 index = pDPA_InsertPtr(hdpa, 0x7fff, lpsice);
467 if ( INVALID_INDEX == index )
468 { SHFree(lpsice);
469 return INVALID_INDEX;
472 index = pImageList_AddIcon (ShellSmallIconList, hSmallIcon);
473 index1= pImageList_AddIcon (ShellBigIconList, hBigIcon);
475 if (index!=index1)
476 { FIXME(shell,"iconlists out of sync 0x%x 0x%x\n", index, index1);
478 lpsice->dwListIndex = index;
480 return lpsice->dwListIndex;
483 /****************************************************************************
484 * SIC_LoadIcon [internal]
485 * NOTES
486 * gets small/big icon by number from a file
488 static INT32 SIC_LoadIcon (LPCSTR sSourceFile, INT32 dwSourceIndex)
489 { HICON32 hiconLarge=0;
490 HICON32 hiconSmall=0;
492 ICO_ExtractIconEx(sSourceFile, &hiconLarge, dwSourceIndex, 1, 32, 32 );
493 ICO_ExtractIconEx(sSourceFile, &hiconSmall, dwSourceIndex, 1, 16, 16 );
496 if ( !hiconLarge || !hiconSmall)
497 { FIXME(shell, "*** failure loading icon %i from %s (%x %x)\n", dwSourceIndex, sSourceFile, hiconLarge, hiconSmall);
498 return -1;
500 return SIC_IconAppend (sSourceFile, dwSourceIndex, hiconSmall, hiconLarge);
502 /*****************************************************************************
503 * SIC_GetIconIndex [internal]
504 * NOTES
505 * look in the cache for a proper icon. if not available the icon is taken
506 * from the file and cached
508 static INT32 SIC_GetIconIndex (LPCSTR sSourceFile, INT32 dwSourceIndex )
509 { SIC_ENTRY sice;
510 INT32 index = INVALID_INDEX;
512 TRACE(shell,"%s %i\n", sSourceFile, dwSourceIndex);
514 sice.sSourceFile = sSourceFile;
515 sice.dwSourceIndex = dwSourceIndex;
517 if (NULL != pDPA_GetPtr (hdpa, 0))
518 { index = pDPA_Search (hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
521 if ( INVALID_INDEX == index )
522 { return SIC_LoadIcon (sSourceFile, dwSourceIndex);
525 TRACE(shell, "-- found\n");
526 return ((LPSIC_ENTRY)pDPA_GetPtr(hdpa, index))->dwListIndex;
528 /****************************************************************************
529 * SIC_LoadIcon [internal]
530 * NOTES
531 * retrives the specified icon from the iconcache. if not found try's to load the icon
533 static HICON32 SIC_GetIcon (LPCSTR sSourceFile, INT32 dwSourceIndex, BOOL32 bSmallIcon )
534 { INT32 index;
536 TRACE(shell,"%s %i\n", sSourceFile, dwSourceIndex);
538 index = SIC_GetIconIndex(sSourceFile, dwSourceIndex);
539 if (INVALID_INDEX == index)
540 { return INVALID_INDEX;
543 if (bSmallIcon)
544 return pImageList_GetIcon(ShellSmallIconList, index, ILD_NORMAL);
545 return pImageList_GetIcon(ShellBigIconList, index, ILD_NORMAL);
548 /*****************************************************************************
549 * SIC_Initialize [internal]
550 * NOTES
551 * hack to load the resources from the shell32.dll under a different dll name
552 * will be removed when the resource-compiler is ready
554 BOOL32 SIC_Initialize(void)
555 { CHAR szShellPath[MAX_PATH];
556 HGLOBAL32 hSmRet, hLgRet;
557 HICON32 *pSmRet, *pLgRet;
558 UINT32 index;
560 TRACE(shell,"\n");
562 if (hdpa) /* already initialized?*/
563 return TRUE;
565 hdpa = pDPA_Create(16);
567 if (!hdpa)
568 { return(FALSE);
571 GetSystemDirectory32A(szShellPath,MAX_PATH);
572 PathAddBackslash32A(szShellPath);
573 strcat(szShellPath,"shell32.dll");
575 hSmRet = GlobalAlloc32( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON32)*40);
576 hLgRet = GlobalAlloc32( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON32)*40);
578 pSmRet = (HICON32*)GlobalLock32(hSmRet);
579 pLgRet = (HICON32*)GlobalLock32(hLgRet);
581 ExtractIconEx32A ( szShellPath, 0, pLgRet, pSmRet, 40 );
583 ShellSmallIconList = pImageList_Create(16,16,ILC_COLORDDB | ILC_MASK,0,0x20);
584 ShellBigIconList = pImageList_Create(32,32,ILC_COLORDDB | ILC_MASK,0,0x20);
586 for (index=0; index<40; index++)
587 { if (! pSmRet[index] )
588 { MSG("*** failure loading resources from %s\n", szShellPath );
589 MSG("*** this is a hack for loading the internal and external dll at the same time\n");
590 MSG("*** you can ignore it but you will miss some icons in win95 dialogs\n\n");
591 break;
593 SIC_IconAppend (szShellPath, index, pSmRet[index], pLgRet[index]);
596 GlobalUnlock32(hLgRet);
597 GlobalFree32(hLgRet);
599 GlobalUnlock32(hSmRet);
600 GlobalFree32(hSmRet);
602 TRACE(shell,"hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList);
604 return TRUE;
607 /*************************************************************************
608 * Shell_GetImageList [SHELL32.71]
610 * PARAMETERS
611 * imglist[1|2] [OUT] pointer which recive imagelist handles
614 DWORD WINAPI Shell_GetImageList(HIMAGELIST * imglist1,HIMAGELIST * imglist2)
615 { TRACE(shell,"(%p,%p)\n",imglist1,imglist2);
616 if (imglist1)
617 { *imglist1=ShellBigIconList;
619 if (imglist2)
620 { *imglist2=ShellSmallIconList;
623 return TRUE;
626 /*************************************************************************
627 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
629 * PARAMETERS
630 * x pointer to an instance of IShellFolder
632 * NOTES
633 * first hack
636 DWORD WINAPI SHMapPIDLToSystemImageListIndex(LPSHELLFOLDER sh,LPITEMIDLIST pidl,DWORD z)
637 { char sTemp[MAX_PATH];
638 DWORD dwNr, ret = INVALID_INDEX;
639 LPITEMIDLIST pidltemp = ILFindLastID(pidl);
641 WARN(shell,"(SF=%p,pidl=%p,0x%08lx)\n",sh,pidl,z);
642 pdump(pidl);
644 if (_ILIsDesktop(pidltemp))
645 { return 34;
647 else if (_ILIsMyComputer(pidltemp))
648 { if (HCR_GetDefaultIcon("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", sTemp, MAX_PATH, &dwNr))
649 { ret = SIC_GetIconIndex(sTemp, dwNr);
650 return (( INVALID_INDEX == ret) ? 15 : ret);
653 else if (_ILIsDrive (pidltemp))
654 { if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
655 { ret = SIC_GetIconIndex(sTemp, dwNr);
656 return (( INVALID_INDEX == ret) ? 8 : ret);
659 else if (_ILIsFolder (pidltemp))
660 { if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
661 { ret = SIC_GetIconIndex(sTemp, dwNr);
662 return (( INVALID_INDEX == ret) ? 3 : ret);
666 if (_ILGetExtension (pidltemp, sTemp, MAX_PATH)) /* object is file */
667 { if ( HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH))
668 { if (HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
669 { if (!strcmp("%1",sTemp)) /* icon is in the file */
670 { _ILGetPidlPath(pidl, sTemp, MAX_PATH);
671 dwNr = 0;
673 ret = SIC_GetIconIndex(sTemp, dwNr);
677 return (( INVALID_INDEX == ret) ? 1 : ret);
680 /*************************************************************************
681 * Shell_GetCachedImageIndex [SHELL32.72]
684 INT32 WINAPI Shell_GetCachedImageIndex32A(LPCSTR szPath, INT32 nIndex, DWORD z)
685 { WARN(shell,"(%s,%08x,%08lx) semi-stub.\n",debugstr_a(szPath),nIndex,z);
686 return SIC_GetIconIndex(szPath, nIndex);
689 INT32 WINAPI Shell_GetCachedImageIndex32W(LPCWSTR szPath, INT32 nIndex, DWORD z)
690 { INT32 ret;
691 LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
693 WARN(shell,"(%s,%08x,%08lx) semi-stub.\n",debugstr_w(szPath),nIndex,z);
695 ret = SIC_GetIconIndex(sTemp, nIndex);
696 HeapFree(GetProcessHeap(),0,sTemp);
697 return ret;
700 INT32 WINAPI Shell_GetCachedImageIndex32AW(LPCVOID szPath, INT32 nIndex, DWORD z)
701 { if( VERSION_OsIsUnicode())
702 return Shell_GetCachedImageIndex32W(szPath, nIndex, z);
703 return Shell_GetCachedImageIndex32A(szPath, nIndex, z);
706 /*************************************************************************
707 * ExtracticonEx32 [shell32.189]
709 HICON32 WINAPI ExtractIconEx32AW ( LPVOID lpszFile, INT32 nIconIndex, HICON32 * phiconLarge, HICON32 * phiconSmall, UINT32 nIcons )
710 { if (VERSION_OsIsUnicode())
711 return ExtractIconEx32W ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
712 return ExtractIconEx32A ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
714 /*************************************************************************
715 * ExtracticonEx32A [shell32.190]
716 * RETURNS
717 * 0 no icon found
718 * 1 file is not valid
719 * HICON32 handle of a icon (phiconLarge/Small == NULL)
721 HICON32 WINAPI ExtractIconEx32A ( LPSTR lpszFile, INT32 nIconIndex, HICON32 * phiconLarge, HICON32 * phiconSmall, UINT32 nIcons )
722 { HICON32 ret=0;
724 TRACE(shell,"file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons );
726 if (nIconIndex==-1) /* Number of icons requested */
727 return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
730 if (phiconLarge)
731 { ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
732 if ( nIcons==1)
733 { ret = phiconLarge[0];
737 /* if no pointers given and one icon expected, return the handle directly*/
738 if (!phiconLarge && ! phiconSmall && nIcons==1 )
739 phiconSmall = &ret;
741 if (phiconSmall)
742 { ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
743 if ( nIcons==1 )
744 { ret = phiconSmall[0];
748 return ret;
750 /*************************************************************************
751 * ExtracticonEx32W [shell32.191]
753 HICON32 WINAPI ExtractIconEx32W ( LPWSTR lpszFile, INT32 nIconIndex, HICON32 * phiconLarge, HICON32 * phiconSmall, UINT32 nIcons )
754 { LPSTR sFile;
755 DWORD ret;
757 TRACE(shell,"file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons );
759 sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
760 ret = ExtractIconEx32A ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
761 HeapFree(GetProcessHeap(),0,sFile);
762 return ret;