Merged msacm and msacm32 dlls.
[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 WINAPI 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         if (!fmapping)
206         {
207           WARN("CreateFileMapping error %ld\n", GetLastError() );
208           goto end_1;
209         }
210
211         if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0))) 
212         {
213           WARN("MapViewOfFile error %ld\n", GetLastError() );
214           goto end_2;
215         }
216
217
218         sig = USER32_GetResourceTable(peimage,&pData);
219
220 /* ico file */
221         if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
222         {
223           BYTE          *pCIDir = 0;
224           NE_TYPEINFO   *pTInfo = (NE_TYPEINFO*)(pData + 2);
225           NE_NAMEINFO   *pIconStorage = NULL;
226           NE_NAMEINFO   *pIconDir = NULL;
227           LPicoICONDIR  lpiID = NULL;
228
229           TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
230
231           if( pData == (BYTE*)-1 )
232           {
233             /* FIXME: pCIDir is allocated on the heap - memory leak */
234             pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize);     /* check for .ICO file */
235             if( pCIDir )
236             {
237               iconDirCount = 1; iconCount = lpiID->idCount;
238               TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
239             }
240           }
241           else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
242           {
243             if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON )      /* find icon directory and icon repository */
244             {
245               iconDirCount = pTInfo->count;
246               pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
247               TRACE("\tfound directory - %i icon families\n", iconDirCount);
248             }
249             if( pTInfo->type_id == NE_RSCTYPE_ICON ) 
250             {
251               iconCount = pTInfo->count;
252               pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
253               TRACE("\ttotal icons - %i\n", iconCount);
254             }
255             pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
256           }
257
258           if( (pIconStorage && pIconDir) || lpiID )       /* load resources and create icons */
259           {
260             if( nIcons == 0 )
261             {
262               hRet = iconDirCount;
263             }
264             else if( nIconIndex < iconDirCount )
265             {
266               UINT16   i, icon;
267               if( nIcons > iconDirCount - nIconIndex ) 
268                 nIcons = iconDirCount - nIconIndex;
269
270               for( i = nIconIndex; i < nIconIndex + nIcons; i++ ) 
271               {
272                 /* .ICO files have only one icon directory */
273                 if( lpiID == NULL )     /* *.ico */
274                   pCIDir = USER32_LoadResource( peimage, pIconDir + i, *(WORD*)pData, &uSize );
275                 RetPtr[i-nIconIndex] = LookupIconIdFromDirectoryEx( pCIDir, TRUE, cxDesired, cyDesired, 0);
276               }
277
278               for( icon = nIconIndex; icon < nIconIndex + nIcons; icon++ )
279               {
280                 pCIDir = NULL;
281                 if( lpiID )
282                   pCIDir = ICO_LoadIcon( peimage, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
283                 else
284                   for( i = 0; i < iconCount; i++ )
285                     if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
286                       pCIDir = USER32_LoadResource( peimage, pIconStorage + i,*(WORD*)pData, &uSize );
287
288                 if( pCIDir )
289                   RetPtr[icon-nIconIndex] = (HICON) CreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
290                 else
291                   RetPtr[icon-nIconIndex] = 0;
292               }
293               hRet = S_OK;
294             }
295           }
296         } 
297 /* end ico file */
298
299 /* exe/dll */
300         else if( sig == IMAGE_NT_SIGNATURE )
301         {
302           LPBYTE                idata,igdata;
303           PIMAGE_DOS_HEADER     dheader;
304           PIMAGE_NT_HEADERS     pe_header;
305           PIMAGE_SECTION_HEADER pe_sections;
306           PIMAGE_RESOURCE_DIRECTORY     rootresdir,iconresdir,icongroupresdir;
307           PIMAGE_RESOURCE_DATA_ENTRY    idataent,igdataent;
308           PIMAGE_RESOURCE_DIRECTORY_ENTRY       xresent;
309           int                   i,j;
310                   
311           dheader = (PIMAGE_DOS_HEADER)peimage;
312           pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);     /* it is a pe header, USER32_GetResourceTable checked that */
313           pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
314           rootresdir = NULL;
315
316           /* search for the root resource directory */
317           for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) 
318           {
319             if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
320               continue;
321             /* FIXME: doesn't work when the resources are not in a seperate section */
322             if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) 
323             {
324               rootresdir = (PIMAGE_RESOURCE_DIRECTORY)(peimage+pe_sections[i].PointerToRawData);
325               break;
326             }
327           }
328
329           if (!rootresdir) 
330           {
331             WARN("haven't found section for resource directory.\n");
332             goto end_3;         /* failure */
333           }
334
335           /* search for the group icon directory */
336           if (!(icongroupresdir = GetResDirEntryW(rootresdir, RT_GROUP_ICONW, (DWORD)rootresdir, FALSE))) 
337           {
338             WARN("No Icongroupresourcedirectory!\n");
339             goto end_3;         /* failure */
340           }
341           iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
342
343           /* only number of icons requested */
344           if( nIcons == 0 )
345           {
346             hRet = iconDirCount;
347             goto end_3;         /* success */
348           }
349
350           if( nIconIndex < 0 )
351           {
352             /* search resource id */
353             int n = 0;
354             int iId = abs(nIconIndex);
355             PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
356
357             while(n<iconDirCount && xprdeTmp)
358             {              
359               if(xprdeTmp->u1.Id ==  iId)
360               {
361                   nIconIndex = n;
362                   break;
363               }
364               n++;
365               xprdeTmp++;                  
366             }
367             if (nIconIndex < 0)
368             {
369               WARN("resource id %d not found\n", iId);
370               goto end_3;               /* failure */
371             }
372           }
373           else
374           {
375             /* check nIconIndex to be in range */
376             if (nIconIndex >= iconDirCount) 
377             {
378               WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
379               goto end_3;               /* failure */
380             }
381           }
382
383           /* assure we don't get too much */
384           if( nIcons > iconDirCount - nIconIndex )
385             nIcons = iconDirCount - nIconIndex;
386
387           /* starting from specified index */
388           xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1) + nIconIndex;
389
390           for (i=0; i < nIcons; i++,xresent++) 
391           {
392             PIMAGE_RESOURCE_DIRECTORY   resdir;
393
394             /* go down this resource entry, name */
395             resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
396
397             /* default language (0) */
398             resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
399             igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
400
401             /* lookup address in mapped image for virtual address */
402             igdata = NULL;
403
404             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
405             {
406               if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
407                 continue;
408               if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
409                 continue;
410               igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
411             }
412
413             if (!igdata) 
414             {
415               WARN("no matching real address for icongroup!\n");
416               goto end_3;       /* failure */
417             }
418             RetPtr[i] = (HICON)LookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
419           }
420
421           if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE))) 
422           {
423             WARN("No Iconresourcedirectory!\n");
424             goto end_3;         /* failure */
425           }
426
427           for (i=0; i<nIcons; i++) 
428           {
429             PIMAGE_RESOURCE_DIRECTORY   xresdir;
430             xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
431             xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
432             idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
433             idata = NULL;
434
435             /* map virtual to address in image */
436             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
437             {
438               if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
439                 continue;
440               if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
441                 continue;
442               idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
443             }
444             if (!idata) 
445             {
446               WARN("no matching real address found for icondata!\n");
447               RetPtr[i]=0;
448               continue;
449             }
450             RetPtr[i] = (HICON) CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
451           }
452           hRet = S_OK;  /* return first icon */
453           goto end_3;           /* sucess */
454         }                       /* if(sig == IMAGE_NT_SIGNATURE) */
455
456 end_3:  UnmapViewOfFile(peimage);       /* success */
457 end_2:  CloseHandle(fmapping);
458 end_1:  _lclose( hFile);
459         return hRet;
460 }
461
462 /***********************************************************************
463  *           PrivateExtractIconsW                       [USER32.@]
464  *
465  * NOTES
466  *  nIndex = 1: a small and a large icon are extracted. 
467  *  the higher word of sizeXY contains the size of the small icon, the lower
468  *  word the size of the big icon. phicon points to HICON[2].
469  *
470  * RETURNS
471  *  nIcons > 0: HRESULT
472  *  nIcons = 0: the number of icons
473  */
474
475 HRESULT WINAPI PrivateExtractIconsW ( 
476         LPCWSTR lpwstrFile,
477         int nIndex,
478         DWORD sizeX,
479         DWORD sizeY,
480         HICON * phicon, /* HICON* */
481         DWORD w,        /* 0 */
482         UINT nIcons,
483         DWORD y )       /* 0x80 maybe LR_* constant */
484 {
485         DWORD ret;
486         TRACE("%s 0x%08x 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
487         debugstr_w(lpwstrFile),nIndex, sizeX ,sizeY ,phicon,w,nIcons,y );
488
489
490         if ((nIcons == 2) && HIWORD(sizeX) && HIWORD(sizeY))
491         {
492           ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, 1, sizeX & 0xffff, sizeY & 0xffff );
493           if (!SUCCEEDED(ret)) return ret;
494           ret = ICO_ExtractIconExW(lpwstrFile, phicon+1, nIndex, 1, (sizeX>>16) & 0xffff, (sizeY>>16) & 0xffff );
495         }
496         else
497         {
498           ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX & 0xffff, sizeY & 0xffff );
499         }
500         
501         FIXME_(icon)("hicon=%08x ret=0x%08lx\n", *phicon, ret);
502         
503         return ret;
504 }
505
506 /***********************************************************************
507  *           PrivateExtractIconsA                       [USER32.@]
508  */
509
510 HRESULT WINAPI PrivateExtractIconsA ( 
511         LPCSTR lpstrFile,
512         DWORD nIndex,
513         DWORD sizeX,
514         DWORD sizeY,
515         HICON * phicon,
516         DWORD w,        /* 0 */
517         UINT  nIcons,
518         DWORD y )       /* 0x80 */
519 {
520         DWORD ret;
521         LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
522         
523         FIXME_(icon)("%s 0x%08lx 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
524         lpstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y );
525
526         ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y);
527
528         FIXME_(icon)("hicon=%08x ret=0x%08lx\n", *phicon, ret);
529         
530         HeapFree(GetProcessHeap(), 0, lpwstrFile);
531         return ret;
532 }
533
534 /***********************************************************************
535  *           PrivateExtractIconExW                      [USER32.443]
536  * NOTES
537  *  if nIcons = -1 it returns the number of icons in any case !!!
538  */
539 HRESULT WINAPI PrivateExtractIconExW (
540         LPCWSTR lpwstrFile,
541         DWORD nIndex,
542         HICON * phIconLarge,
543         HICON * phIconSmall,
544         UINT nIcons )
545 {
546         DWORD cyicon, cysmicon, cxicon, cxsmicon;
547         HRESULT ret = 0;
548
549         TRACE("%s 0x%08lx %p %p 0x%08x\n",
550         debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
551         
552         if (nIndex == 1 && phIconSmall && phIconLarge)
553         {
554           HICON hIcon[2];
555           cxicon = GetSystemMetrics(SM_CXICON);
556           cyicon = GetSystemMetrics(SM_CYICON);
557           cxsmicon = GetSystemMetrics(SM_CXSMICON);
558           cysmicon = GetSystemMetrics(SM_CYSMICON);
559         
560           ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon | (cxsmicon<<16),  cyicon | (cysmicon<<16),
561           (HICON*) &hIcon, 0, 2, 0 );
562           *phIconLarge = hIcon[0];
563           *phIconSmall = hIcon[1];
564           return ret;
565         }
566
567         if (nIndex != -1)
568         {
569           if (phIconSmall)
570           {
571             /* extract n small icons */
572             cxsmicon = GetSystemMetrics(SM_CXSMICON);
573             cysmicon = GetSystemMetrics(SM_CYSMICON);
574             ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxsmicon, cysmicon, phIconSmall, 0, nIcons, 0 );
575           }
576           if (phIconLarge )
577           {
578             /* extract n large icons */
579             cxicon = GetSystemMetrics(SM_CXICON);
580             cyicon = GetSystemMetrics(SM_CYICON);
581             ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon, cyicon, phIconLarge, 0, nIcons, 0 );
582           }
583           return ret;
584         }
585
586         /* get the number of icons */
587         return PrivateExtractIconsW ( lpwstrFile, 0, 0, 0, 0, 0, 0, 0 );
588 }
589
590 /***********************************************************************
591  *           PrivateExtractIconExA                      [USER32.442]
592  */
593 HRESULT WINAPI PrivateExtractIconExA (
594         LPCSTR lpstrFile,
595         DWORD nIndex,
596         HICON * phIconLarge,
597         HICON * phIconSmall,
598         UINT nIcons )
599 {
600         DWORD ret;
601         LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
602
603         TRACE("%s 0x%08lx %p %p 0x%08x\n",
604         lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
605
606         ret = PrivateExtractIconExW(lpwstrFile,nIndex,phIconLarge, phIconSmall, nIcons);
607
608         HeapFree(GetProcessHeap(), 0, lpwstrFile);
609         return ret;
610 }
611