Use a binary search to find entries in resource directories.
[wine] / dlls / user / exticon.c
1 /*
2  *      icon extracting
3  *
4  * taken and slightly changed from shell
5  * this should replace the icon extraction code in shell32 and shell16 once
6  * it needs a serious test for compliance with the native API 
7  */
8 #include <string.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include "winbase.h"
12 #include "windef.h"
13 #include "winerror.h"
14 #include "wingdi.h"
15 #include "winuser.h"
16 #include "neexe.h"
17 #include "cursoricon.h"
18 #include "module.h"
19 #include "heap.h"
20 #include "debugtools.h"
21
22 DEFAULT_DEBUG_CHANNEL(icon)
23
24 #include "pshpack1.h"
25
26 typedef struct
27 {
28     BYTE        bWidth;          /* Width, in pixels, of the image      */
29     BYTE        bHeight;         /* Height, in pixels, of the image     */
30     BYTE        bColorCount;     /* Number of colors in image (0 if >=8bpp) */
31     BYTE        bReserved;       /* Reserved ( must be 0)               */
32     WORD        wPlanes;         /* Color Planes                        */
33     WORD        wBitCount;       /* Bits per pixel                      */
34     DWORD       dwBytesInRes;    /* How many bytes in this resource?    */
35     DWORD       dwImageOffset;   /* Where in the file is this image?    */
36 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
37
38 typedef struct
39 {
40     WORD            idReserved;   /* Reserved (must be 0) */
41     WORD            idType;       /* Resource Type (RES_ICON or RES_CURSOR) */
42     WORD            idCount;      /* How many images */
43     icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
44 } icoICONDIR, *LPicoICONDIR;
45
46 #include "poppack.h"
47
48 #if 0
49 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
50 {       
51         TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
52         TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
53         TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n", 
54         entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
55 }
56 static void dumpIcoDir ( LPicoICONDIR entry )
57 {       
58         TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
59 }
60 #endif
61 /*************************************************************************
62  *                              USER32_GetResourceTable
63  */
64 static DWORD USER32_GetResourceTable(LPBYTE peimage, LPBYTE *retptr)
65 {
66         IMAGE_DOS_HEADER        * mz_header;
67
68         TRACE("%p %p\n", peimage, retptr);  
69
70         *retptr = NULL;
71
72         mz_header = (IMAGE_DOS_HEADER*) peimage;
73         
74         if (mz_header->e_magic != IMAGE_DOS_SIGNATURE)
75         {
76           if (mz_header->e_cblp == 1)   /* .ICO file ? */
77           {
78             *retptr = (LPBYTE)-1;       /* ICONHEADER.idType, must be 1 */
79             return 1;
80           }
81           else
82             return 0; /* failed */
83         }
84         
85         if (*((DWORD*)(peimage + mz_header->e_lfanew)) == IMAGE_NT_SIGNATURE )
86           return IMAGE_NT_SIGNATURE;
87
88         if (*((WORD*)(peimage + mz_header->e_lfanew)) == IMAGE_OS2_SIGNATURE )
89         {
90           IMAGE_OS2_HEADER      * ne_header;
91
92           ne_header = (IMAGE_OS2_HEADER*)(peimage + mz_header->e_lfanew);
93           
94           if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE)
95             return 0;
96
97           if( (ne_header->ne_restab - ne_header->ne_rsrctab) <= sizeof(NE_TYPEINFO) )
98             *retptr = (LPBYTE)-1;
99           else
100             *retptr = peimage + mz_header->e_lfanew + ne_header->ne_rsrctab;
101
102           return IMAGE_OS2_SIGNATURE;
103         }
104         return 0; /* failed */
105 }
106 /*************************************************************************
107  *                      USER32_LoadResource
108  */
109 static BYTE * USER32_LoadResource( LPBYTE peimage, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
110 {
111         TRACE("%p %p 0x%08x\n", peimage, pNInfo, sizeShift);
112
113         *uSize = (DWORD)pNInfo->length << sizeShift;
114         return peimage + ((DWORD)pNInfo->offset << sizeShift);
115 }
116
117 /*************************************************************************
118  *                      ICO_LoadIcon
119  */
120 static BYTE * ICO_LoadIcon( LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
121 {
122         TRACE("%p %p\n", peimage, lpiIDE);
123
124         *uSize = lpiIDE->dwBytesInRes;
125         return peimage + lpiIDE->dwImageOffset;
126 }
127
128 /*************************************************************************
129  *                      ICO_GetIconDirectory
130  *
131  * Reads .ico file and build phony ICONDIR struct
132  * see http://www.microsoft.com/win32dev/ui/icons.htm
133  */
134 #define HEADER_SIZE             (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
135 #define HEADER_SIZE_FILE        (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
136
137 static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG *uSize ) 
138 {
139         CURSORICONDIR   * lpcid;        /* icon resource in resource-dir format */
140         CURSORICONDIR   * lpID;         /* icon resource in resource format */
141         int             i;
142
143         TRACE("%p %p\n", peimage, lplpiID); 
144         
145         lpcid = (CURSORICONDIR*)peimage;
146
147         if( lpcid->idReserved || (lpcid->idType != 1) || (!lpcid->idCount) )
148           return 0;
149
150         /* allocate the phony ICONDIR structure */
151         *uSize = lpcid->idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
152         if( (lpID = (CURSORICONDIR*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
153         {
154           /* copy the header */
155           lpID->idReserved = lpcid->idReserved;
156           lpID->idType = lpcid->idType;
157           lpID->idCount = lpcid->idCount;
158
159           /* copy the entrys */
160           for( i=0; i < lpcid->idCount; i++ )
161           {
162             memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpcid->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
163             lpID->idEntries[i].wResId = i;
164           }
165
166           *lplpiID = (LPicoICONDIR)peimage;
167           return (BYTE *)lpID;
168         }
169         return 0;
170 }
171
172 /*************************************************************************
173  *      ICO_ExtractIconExW              [internal]
174  *
175  * NOTES
176  *  nIcons = 0: returns number of Icons in file
177  *
178  * returns
179  *  failure:0; success: icon handle or nr of icons (nIconIndex-1)
180  */
181 static HRESULT ICO_ExtractIconExW(
182         LPCWSTR lpszExeFileName,
183         HICON * RetPtr,
184         INT nIconIndex,
185         UINT nIcons,
186         UINT cxDesired,
187         UINT cyDesired )
188 {
189         HGLOBAL         hRet = E_FAIL;
190         LPBYTE          pData;
191         DWORD           sig;
192         HFILE           hFile;
193         UINT16          iconDirCount = 0,iconCount = 0;
194         LPBYTE          peimage;
195         HANDLE          fmapping;
196         ULONG           uSize;
197         
198         TRACE("(file %s,start %d,extract %d\n", debugstr_w(lpszExeFileName), nIconIndex, nIcons);
199
200         hFile = CreateFileW( lpszExeFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, -1 );
201         if (hFile == INVALID_HANDLE_VALUE) return hRet;
202
203         /* Map the file */
204         fmapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL );
205         CloseHandle( hFile );
206         if (!fmapping)
207         {
208           WARN("CreateFileMapping error %ld\n", GetLastError() );
209           return hRet;
210         }
211
212         if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0))) 
213         {
214           WARN("MapViewOfFile error %ld\n", GetLastError() );
215           CloseHandle( fmapping );
216           return hRet;
217         }
218         CloseHandle( fmapping );
219
220         sig = USER32_GetResourceTable(peimage,&pData);
221
222 /* ico file */
223         if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
224         {
225           BYTE          *pCIDir = 0;
226           NE_TYPEINFO   *pTInfo = (NE_TYPEINFO*)(pData + 2);
227           NE_NAMEINFO   *pIconStorage = NULL;
228           NE_NAMEINFO   *pIconDir = NULL;
229           LPicoICONDIR  lpiID = NULL;
230
231           TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
232
233           if( pData == (BYTE*)-1 )
234           {
235             /* FIXME: pCIDir is allocated on the heap - memory leak */
236             pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize);     /* check for .ICO file */
237             if( pCIDir )
238             {
239               iconDirCount = 1; iconCount = lpiID->idCount;
240               TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
241             }
242           }
243           else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
244           {
245             if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON )      /* find icon directory and icon repository */
246             {
247               iconDirCount = pTInfo->count;
248               pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
249               TRACE("\tfound directory - %i icon families\n", iconDirCount);
250             }
251             if( pTInfo->type_id == NE_RSCTYPE_ICON ) 
252             {
253               iconCount = pTInfo->count;
254               pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
255               TRACE("\ttotal icons - %i\n", iconCount);
256             }
257             pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
258           }
259
260           if( (pIconStorage && pIconDir) || lpiID )       /* load resources and create icons */
261           {
262             if( nIcons == 0 )
263             {
264               hRet = iconDirCount;
265             }
266             else if( nIconIndex < iconDirCount )
267             {
268               UINT16   i, icon;
269               if( nIcons > iconDirCount - nIconIndex ) 
270                 nIcons = iconDirCount - nIconIndex;
271
272               for( i = nIconIndex; i < nIconIndex + nIcons; i++ ) 
273               {
274                 /* .ICO files have only one icon directory */
275                 if( lpiID == NULL )     /* *.ico */
276                   pCIDir = USER32_LoadResource( peimage, pIconDir + i, *(WORD*)pData, &uSize );
277                 RetPtr[i-nIconIndex] = LookupIconIdFromDirectoryEx( pCIDir, TRUE, cxDesired, cyDesired, 0);
278               }
279
280               for( icon = nIconIndex; icon < nIconIndex + nIcons; icon++ )
281               {
282                 pCIDir = NULL;
283                 if( lpiID )
284                   pCIDir = ICO_LoadIcon( peimage, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
285                 else
286                   for( i = 0; i < iconCount; i++ )
287                     if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
288                       pCIDir = USER32_LoadResource( peimage, pIconStorage + i,*(WORD*)pData, &uSize );
289
290                 if( pCIDir )
291                   RetPtr[icon-nIconIndex] = (HICON) CreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
292                 else
293                   RetPtr[icon-nIconIndex] = 0;
294               }
295               hRet = S_OK;
296             }
297           }
298         } 
299 /* end ico file */
300
301 /* exe/dll */
302         else if( sig == IMAGE_NT_SIGNATURE )
303         {
304           LPBYTE                idata,igdata;
305           PIMAGE_DOS_HEADER     dheader;
306           PIMAGE_NT_HEADERS     pe_header;
307           PIMAGE_SECTION_HEADER pe_sections;
308           const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
309           const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
310           const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
311           int                   i,j;
312                   
313           dheader = (PIMAGE_DOS_HEADER)peimage;
314           pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);     /* it is a pe header, USER32_GetResourceTable checked that */
315           pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
316           rootresdir = NULL;
317
318           /* search for the root resource directory */
319           for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) 
320           {
321             if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
322               continue;
323             /* FIXME: doesn't work when the resources are not in a seperate section */
324             if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) 
325             {
326               rootresdir = (PIMAGE_RESOURCE_DIRECTORY)(peimage+pe_sections[i].PointerToRawData);
327               break;
328             }
329           }
330
331           if (!rootresdir) 
332           {
333             WARN("haven't found section for resource directory.\n");
334             goto end;           /* failure */
335           }
336
337           /* search for the group icon directory */
338           if (!(icongroupresdir = GetResDirEntryW(rootresdir, RT_GROUP_ICONW, rootresdir, FALSE))) 
339           {
340             WARN("No Icongroupresourcedirectory!\n");
341             goto end;           /* failure */
342           }
343           iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
344
345           /* only number of icons requested */
346           if( nIcons == 0 )
347           {
348             hRet = iconDirCount;
349             goto end;           /* success */
350           }
351
352           if( nIconIndex < 0 )
353           {
354             /* search resource id */
355             int n = 0;
356             int iId = abs(nIconIndex);
357             PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
358
359             while(n<iconDirCount && xprdeTmp)
360             {              
361               if(xprdeTmp->u1.Id ==  iId)
362               {
363                   nIconIndex = n;
364                   break;
365               }
366               n++;
367               xprdeTmp++;                  
368             }
369             if (nIconIndex < 0)
370             {
371               WARN("resource id %d not found\n", iId);
372               goto end;         /* failure */
373             }
374           }
375           else
376           {
377             /* check nIconIndex to be in range */
378             if (nIconIndex >= iconDirCount) 
379             {
380               WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
381               goto end;         /* failure */
382             }
383           }
384
385           /* assure we don't get too much */
386           if( nIcons > iconDirCount - nIconIndex )
387             nIcons = iconDirCount - nIconIndex;
388
389           /* starting from specified index */
390           xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1) + nIconIndex;
391
392           for (i=0; i < nIcons; i++,xresent++) 
393           {
394               const IMAGE_RESOURCE_DIRECTORY *resdir;
395
396             /* go down this resource entry, name */
397             resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
398
399             /* default language (0) */
400             resdir = GetResDirEntryW(resdir,(LPWSTR)0,rootresdir,TRUE);
401             igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
402
403             /* lookup address in mapped image for virtual address */
404             igdata = NULL;
405
406             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
407             {
408               if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
409                 continue;
410               if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
411                 continue;
412               igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
413             }
414
415             if (!igdata) 
416             {
417               WARN("no matching real address for icongroup!\n");
418               goto end; /* failure */
419             }
420             RetPtr[i] = (HICON)LookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
421           }
422
423           if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,rootresdir,FALSE))) 
424           {
425             WARN("No Iconresourcedirectory!\n");
426             goto end;           /* failure */
427           }
428
429           for (i=0; i<nIcons; i++) 
430           {
431               const IMAGE_RESOURCE_DIRECTORY *xresdir;
432             xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],rootresdir,FALSE);
433             xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,rootresdir,TRUE);
434             idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
435             idata = NULL;
436
437             /* map virtual to address in image */
438             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
439             {
440               if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
441                 continue;
442               if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
443                 continue;
444               idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
445             }
446             if (!idata) 
447             {
448               WARN("no matching real address found for icondata!\n");
449               RetPtr[i]=0;
450               continue;
451             }
452             RetPtr[i] = (HICON) CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
453           }
454           hRet = S_OK;  /* return first icon */
455         }                       /* if(sig == IMAGE_NT_SIGNATURE) */
456
457 end:    UnmapViewOfFile(peimage);       /* success */
458         return hRet;
459 }
460
461 /***********************************************************************
462  *           PrivateExtractIconsW                       [USER32.@]
463  *
464  * NOTES
465  *  nIndex = 1: a small and a large icon are extracted. 
466  *  the higher word of sizeXY contains the size of the small icon, the lower
467  *  word the size of the big icon. phicon points to HICON[2].
468  *
469  * RETURNS
470  *  nIcons > 0: HRESULT
471  *  nIcons = 0: the number of icons
472  */
473
474 HRESULT WINAPI PrivateExtractIconsW ( 
475         LPCWSTR lpwstrFile,
476         int nIndex,
477         DWORD sizeX,
478         DWORD sizeY,
479         HICON * phicon, /* HICON* */
480         DWORD w,        /* 0 */
481         UINT nIcons,
482         DWORD y )       /* 0x80 maybe LR_* constant */
483 {
484         DWORD ret;
485         TRACE("%s 0x%08x 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
486         debugstr_w(lpwstrFile),nIndex, sizeX ,sizeY ,phicon,w,nIcons,y );
487
488
489         if ((nIcons == 2) && HIWORD(sizeX) && HIWORD(sizeY))
490         {
491           ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, 1, sizeX & 0xffff, sizeY & 0xffff );
492           if (!SUCCEEDED(ret)) return ret;
493           ret = ICO_ExtractIconExW(lpwstrFile, phicon+1, nIndex, 1, (sizeX>>16) & 0xffff, (sizeY>>16) & 0xffff );
494         }
495         else
496         {
497           ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX & 0xffff, sizeY & 0xffff );
498         }
499         
500         FIXME_(icon)("hicon=%08x ret=0x%08lx\n", *phicon, ret);
501         
502         return ret;
503 }
504
505 /***********************************************************************
506  *           PrivateExtractIconsA                       [USER32.@]
507  */
508
509 HRESULT WINAPI PrivateExtractIconsA ( 
510         LPCSTR lpstrFile,
511         INT nIndex,
512         DWORD sizeX,
513         DWORD sizeY,
514         HICON * phicon,
515         DWORD w,        /* 0 */
516         UINT  nIcons,
517         DWORD y )       /* 0x80 */
518 {
519         DWORD ret;
520         LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
521         
522         FIXME_(icon)("%s 0x%08x 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
523         lpstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y );
524
525         ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y);
526
527         FIXME_(icon)("hicon=%08x ret=0x%08lx\n", *phicon, ret);
528         
529         HeapFree(GetProcessHeap(), 0, lpwstrFile);
530         return ret;
531 }
532
533 /***********************************************************************
534  *           PrivateExtractIconExW                      [USER32.443]
535  * NOTES
536  *  if nIcons = -1 it returns the number of icons in any case !!!
537  */
538 HRESULT WINAPI PrivateExtractIconExW (
539         LPCWSTR lpwstrFile,
540         DWORD nIndex,
541         HICON * phIconLarge,
542         HICON * phIconSmall,
543         UINT nIcons )
544 {
545         DWORD cyicon, cysmicon, cxicon, cxsmicon;
546         HRESULT ret = 0;
547
548         TRACE("%s 0x%08lx %p %p 0x%08x\n",
549         debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
550         
551         if (nIndex == 1 && phIconSmall && phIconLarge)
552         {
553           HICON hIcon[2];
554           cxicon = GetSystemMetrics(SM_CXICON);
555           cyicon = GetSystemMetrics(SM_CYICON);
556           cxsmicon = GetSystemMetrics(SM_CXSMICON);
557           cysmicon = GetSystemMetrics(SM_CYSMICON);
558         
559           ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon | (cxsmicon<<16),  cyicon | (cysmicon<<16),
560           (HICON*) &hIcon, 0, 2, 0 );
561           *phIconLarge = hIcon[0];
562           *phIconSmall = hIcon[1];
563           return ret;
564         }
565
566         if (nIndex != -1)
567         {
568           if (phIconSmall)
569           {
570             /* extract n small icons */
571             cxsmicon = GetSystemMetrics(SM_CXSMICON);
572             cysmicon = GetSystemMetrics(SM_CYSMICON);
573             ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxsmicon, cysmicon, phIconSmall, 0, nIcons, 0 );
574           }
575           if (phIconLarge )
576           {
577             /* extract n large icons */
578             cxicon = GetSystemMetrics(SM_CXICON);
579             cyicon = GetSystemMetrics(SM_CYICON);
580             ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon, cyicon, phIconLarge, 0, nIcons, 0 );
581           }
582           return ret;
583         }
584
585         /* get the number of icons */
586         return PrivateExtractIconsW ( lpwstrFile, 0, 0, 0, 0, 0, 0, 0 );
587 }
588
589 /***********************************************************************
590  *           PrivateExtractIconExA                      [USER32.442]
591  */
592 HRESULT WINAPI PrivateExtractIconExA (
593         LPCSTR lpstrFile,
594         DWORD nIndex,
595         HICON * phIconLarge,
596         HICON * phIconSmall,
597         UINT nIcons )
598 {
599         DWORD ret;
600         LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
601
602         TRACE("%s 0x%08lx %p %p 0x%08x\n",
603         lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
604
605         ret = PrivateExtractIconExW(lpwstrFile,nIndex,phIconLarge, phIconSmall, nIcons);
606
607         HeapFree(GetProcessHeap(), 0, lpwstrFile);
608         return ret;
609 }
610