Warning fixes.
[wine.git] / dlls / user / exticon.c
blobadb05ea5e0c58d07ff7995dd1283b7cdc22309ee
1 /*
2 * icon extracting
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 <stdlib.h> /* abs() */
10 #include <sys/types.h>
11 #include <unistd.h>
12 #include "config.h"
13 #include "winbase.h"
14 #include "windef.h"
15 #include "winerror.h"
16 #include "wingdi.h"
17 #include "winuser.h"
18 #include "wine/winbase16.h"
19 #include "cursoricon.h"
20 #include "heap.h"
21 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(icon);
25 #include "pshpack1.h"
27 typedef struct
29 BYTE bWidth; /* Width, in pixels, of the image */
30 BYTE bHeight; /* Height, in pixels, of the image */
31 BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
32 BYTE bReserved; /* Reserved ( must be 0) */
33 WORD wPlanes; /* Color Planes */
34 WORD wBitCount; /* Bits per pixel */
35 DWORD dwBytesInRes; /* How many bytes in this resource? */
36 DWORD dwImageOffset; /* Where in the file is this image? */
37 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
39 typedef struct
41 WORD idReserved; /* Reserved (must be 0) */
42 WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
43 WORD idCount; /* How many images */
44 icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
45 } icoICONDIR, *LPicoICONDIR;
47 #include "poppack.h"
49 #if 0
50 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
52 TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
53 TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
54 TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
55 entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
57 static void dumpIcoDir ( LPicoICONDIR entry )
59 TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
61 #endif
63 /**********************************************************************
64 * find_entry_by_id
66 * Find an entry by id in a resource directory
67 * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
69 static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
70 WORD id, const void *root )
72 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
73 int min, max, pos;
75 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
76 min = dir->NumberOfNamedEntries;
77 max = min + dir->NumberOfIdEntries - 1;
78 while (min <= max)
80 pos = (min + max) / 2;
81 if (entry[pos].u1.s2.Id == id)
82 return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].u2.s3.OffsetToDirectory);
83 if (entry[pos].u1.s2.Id > id) max = pos - 1;
84 else min = pos + 1;
86 return NULL;
89 /**********************************************************************
90 * find_entry_default
92 * Find a default entry in a resource directory
93 * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
95 static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
96 const void *root )
98 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
99 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
100 return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry->u2.s3.OffsetToDirectory);
103 /*************************************************************************
104 * USER32_GetResourceTable
106 static DWORD USER32_GetResourceTable(LPBYTE peimage,DWORD pesize,LPBYTE *retptr)
108 IMAGE_DOS_HEADER * mz_header;
110 TRACE("%p %p\n", peimage, retptr);
112 *retptr = NULL;
114 mz_header = (IMAGE_DOS_HEADER*) peimage;
116 if (mz_header->e_magic != IMAGE_DOS_SIGNATURE)
118 if (mz_header->e_cblp == 1) /* .ICO file ? */
120 *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
121 return 1;
123 else
124 return 0; /* failed */
126 if (mz_header->e_lfanew >= pesize) {
127 return 0; /* failed, happens with PKZIP DOS Exes for instance. */
129 if (*((DWORD*)(peimage + mz_header->e_lfanew)) == IMAGE_NT_SIGNATURE )
130 return IMAGE_NT_SIGNATURE;
132 if (*((WORD*)(peimage + mz_header->e_lfanew)) == IMAGE_OS2_SIGNATURE )
134 IMAGE_OS2_HEADER * ne_header;
136 ne_header = (IMAGE_OS2_HEADER*)(peimage + mz_header->e_lfanew);
138 if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE)
139 return 0;
141 if( (ne_header->ne_restab - ne_header->ne_rsrctab) <= sizeof(NE_TYPEINFO) )
142 *retptr = (LPBYTE)-1;
143 else
144 *retptr = peimage + mz_header->e_lfanew + ne_header->ne_rsrctab;
146 return IMAGE_OS2_SIGNATURE;
148 return 0; /* failed */
150 /*************************************************************************
151 * USER32_LoadResource
153 static BYTE * USER32_LoadResource( LPBYTE peimage, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
155 TRACE("%p %p 0x%08x\n", peimage, pNInfo, sizeShift);
157 *uSize = (DWORD)pNInfo->length << sizeShift;
158 return peimage + ((DWORD)pNInfo->offset << sizeShift);
161 /*************************************************************************
162 * ICO_LoadIcon
164 static BYTE * ICO_LoadIcon( LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
166 TRACE("%p %p\n", peimage, lpiIDE);
168 *uSize = lpiIDE->dwBytesInRes;
169 return peimage + lpiIDE->dwImageOffset;
172 /*************************************************************************
173 * ICO_GetIconDirectory
175 * Reads .ico file and build phony ICONDIR struct
176 * see http://www.microsoft.com/win32dev/ui/icons.htm
178 #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
179 #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
181 static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG *uSize )
183 CURSORICONDIR * lpcid; /* icon resource in resource-dir format */
184 CURSORICONDIR * lpID; /* icon resource in resource format */
185 int i;
187 TRACE("%p %p\n", peimage, lplpiID);
189 lpcid = (CURSORICONDIR*)peimage;
191 if( lpcid->idReserved || (lpcid->idType != 1) || (!lpcid->idCount) )
192 return 0;
194 /* allocate the phony ICONDIR structure */
195 *uSize = lpcid->idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
196 if( (lpID = (CURSORICONDIR*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
198 /* copy the header */
199 lpID->idReserved = lpcid->idReserved;
200 lpID->idType = lpcid->idType;
201 lpID->idCount = lpcid->idCount;
203 /* copy the entrys */
204 for( i=0; i < lpcid->idCount; i++ )
206 memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpcid->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
207 lpID->idEntries[i].wResId = i;
210 *lplpiID = (LPicoICONDIR)peimage;
211 return (BYTE *)lpID;
213 return 0;
216 /*************************************************************************
217 * ICO_ExtractIconExW [internal]
219 * NOTES
220 * nIcons = 0: returns number of Icons in file
222 * returns
223 * failure:0; success: icon handle or nr of icons (nIconIndex-1)
225 static HRESULT ICO_ExtractIconExW(
226 LPCWSTR lpszExeFileName,
227 HICON * RetPtr,
228 INT nIconIndex,
229 UINT nIcons,
230 UINT cxDesired,
231 UINT cyDesired )
233 HGLOBAL hRet = E_FAIL;
234 LPBYTE pData;
235 DWORD sig;
236 HFILE hFile;
237 UINT16 iconDirCount = 0,iconCount = 0;
238 LPBYTE peimage;
239 HANDLE fmapping;
240 ULONG uSize;
241 DWORD fsizeh,fsizel;
243 TRACE("(file %s,start %d,extract %d\n", debugstr_w(lpszExeFileName), nIconIndex, nIcons);
245 hFile = CreateFileW( lpszExeFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
246 if (hFile == INVALID_HANDLE_VALUE) return hRet;
247 fsizel = GetFileSize(hFile,&fsizeh);
249 /* Map the file */
250 fmapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL );
251 CloseHandle( hFile );
252 if (!fmapping)
254 WARN("CreateFileMapping error %ld\n", GetLastError() );
255 return hRet;
258 if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
260 WARN("MapViewOfFile error %ld\n", GetLastError() );
261 CloseHandle( fmapping );
262 return hRet;
264 CloseHandle( fmapping );
266 sig = USER32_GetResourceTable(peimage,fsizel,&pData);
268 /* ico file */
269 if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
271 BYTE *pCIDir = 0;
272 NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
273 NE_NAMEINFO *pIconStorage = NULL;
274 NE_NAMEINFO *pIconDir = NULL;
275 LPicoICONDIR lpiID = NULL;
277 TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
279 if( pData == (BYTE*)-1 )
281 /* FIXME: pCIDir is allocated on the heap - memory leak */
282 pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize); /* check for .ICO file */
283 if( pCIDir )
285 iconDirCount = 1; iconCount = lpiID->idCount;
286 TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
289 else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
291 if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
293 iconDirCount = pTInfo->count;
294 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
295 TRACE("\tfound directory - %i icon families\n", iconDirCount);
297 if( pTInfo->type_id == NE_RSCTYPE_ICON )
299 iconCount = pTInfo->count;
300 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
301 TRACE("\ttotal icons - %i\n", iconCount);
303 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
306 if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
308 if( nIcons == 0 )
310 hRet = iconDirCount;
312 else if( nIconIndex < iconDirCount )
314 UINT16 i, icon;
315 if( nIcons > iconDirCount - nIconIndex )
316 nIcons = iconDirCount - nIconIndex;
318 for( i = nIconIndex; i < nIconIndex + nIcons; i++ )
320 /* .ICO files have only one icon directory */
321 if( lpiID == NULL ) /* *.ico */
322 pCIDir = USER32_LoadResource( peimage, pIconDir + i, *(WORD*)pData, &uSize );
323 RetPtr[i-nIconIndex] = LookupIconIdFromDirectoryEx( pCIDir, TRUE, cxDesired, cyDesired, 0);
326 for( icon = nIconIndex; icon < nIconIndex + nIcons; icon++ )
328 pCIDir = NULL;
329 if( lpiID )
330 pCIDir = ICO_LoadIcon( peimage, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
331 else
332 for( i = 0; i < iconCount; i++ )
333 if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
334 pCIDir = USER32_LoadResource( peimage, pIconStorage + i,*(WORD*)pData, &uSize );
336 if( pCIDir )
337 RetPtr[icon-nIconIndex] = (HICON) CreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
338 else
339 RetPtr[icon-nIconIndex] = 0;
341 hRet = S_OK;
345 /* end ico file */
347 /* exe/dll */
348 else if( sig == IMAGE_NT_SIGNATURE )
350 LPBYTE idata,igdata;
351 PIMAGE_DOS_HEADER dheader;
352 PIMAGE_NT_HEADERS pe_header;
353 PIMAGE_SECTION_HEADER pe_sections;
354 const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
355 const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
356 const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
357 int i,j;
359 dheader = (PIMAGE_DOS_HEADER)peimage;
360 pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, USER32_GetResourceTable checked that */
361 pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
362 rootresdir = NULL;
364 /* search for the root resource directory */
365 for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
367 if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
368 continue;
369 if (fsizel < pe_sections[i].PointerToRawData+pe_sections[i].SizeOfRawData) {
370 FIXME("File %s too short (section is at %ld bytes, real size is %ld)\n",
371 debugstr_w(lpszExeFileName),
372 pe_sections[i].PointerToRawData+pe_sections[i].SizeOfRawData,
373 fsizel
375 goto end;
377 /* FIXME: doesn't work when the resources are not in a seperate section */
378 if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
380 rootresdir = (PIMAGE_RESOURCE_DIRECTORY)(peimage+pe_sections[i].PointerToRawData);
381 break;
385 if (!rootresdir)
387 WARN("haven't found section for resource directory.\n");
388 goto end; /* failure */
391 /* search for the group icon directory */
392 if (!(icongroupresdir = find_entry_by_id(rootresdir, LOWORD(RT_GROUP_ICONW), rootresdir)))
394 WARN("No Icongroupresourcedirectory!\n");
395 goto end; /* failure */
397 iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
399 /* only number of icons requested */
400 if( nIcons == 0 )
402 hRet = iconDirCount;
403 goto end; /* success */
406 if( nIconIndex < 0 )
408 /* search resource id */
409 int n = 0;
410 int iId = abs(nIconIndex);
411 PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
413 while(n<iconDirCount && xprdeTmp)
415 if(xprdeTmp->u1.s2.Id == iId)
417 nIconIndex = n;
418 break;
420 n++;
421 xprdeTmp++;
423 if (nIconIndex < 0)
425 WARN("resource id %d not found\n", iId);
426 goto end; /* failure */
429 else
431 /* check nIconIndex to be in range */
432 if (nIconIndex >= iconDirCount)
434 WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
435 goto end; /* failure */
439 /* assure we don't get too much */
440 if( nIcons > iconDirCount - nIconIndex )
441 nIcons = iconDirCount - nIconIndex;
443 /* starting from specified index */
444 xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1) + nIconIndex;
446 for (i=0; i < nIcons; i++,xresent++)
448 const IMAGE_RESOURCE_DIRECTORY *resdir;
450 /* go down this resource entry, name */
451 resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s3.OffsetToDirectory));
453 /* default language (0) */
454 resdir = find_entry_default(resdir,rootresdir);
455 igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
457 /* lookup address in mapped image for virtual address */
458 igdata = NULL;
460 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
462 if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
463 continue;
464 if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
465 continue;
467 if (igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData+igdataent->Size > fsizel) {
468 FIXME("overflow in PE lookup (%s has len %ld, have offset %ld), short file?\n",debugstr_w(lpszExeFileName),fsizel,igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData+igdataent->Size);
469 goto end; /* failure */
471 igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
474 if (!igdata)
476 FIXME("no matching real address for icongroup!\n");
477 goto end; /* failure */
479 RetPtr[i] = (HICON)LookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
482 if (!(iconresdir=find_entry_by_id(rootresdir,LOWORD(RT_ICONW),rootresdir)))
484 WARN("No Iconresourcedirectory!\n");
485 goto end; /* failure */
488 for (i=0; i<nIcons; i++)
490 const IMAGE_RESOURCE_DIRECTORY *xresdir;
491 xresdir = find_entry_by_id(iconresdir,RetPtr[i],rootresdir);
492 xresdir = find_entry_default(xresdir,rootresdir);
493 idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
494 idata = NULL;
496 /* map virtual to address in image */
497 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
499 if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
500 continue;
501 if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
502 continue;
503 idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
505 if (!idata)
507 WARN("no matching real address found for icondata!\n");
508 RetPtr[i]=0;
509 continue;
511 RetPtr[i] = (HICON) CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
513 hRet = S_OK; /* return first icon */
514 } /* if(sig == IMAGE_NT_SIGNATURE) */
516 end: UnmapViewOfFile(peimage); /* success */
517 return hRet;
520 /***********************************************************************
521 * PrivateExtractIconsW [USER32.@]
523 * NOTES
524 * nIndex = 1: a small and a large icon are extracted.
525 * the higher word of sizeXY contains the size of the small icon, the lower
526 * word the size of the big icon. phicon points to HICON[2].
528 * RETURNS
529 * nIcons > 0: HRESULT
530 * nIcons = 0: the number of icons
533 HRESULT WINAPI PrivateExtractIconsW (
534 LPCWSTR lpwstrFile,
535 int nIndex,
536 DWORD sizeX,
537 DWORD sizeY,
538 HICON * phicon, /* [???] NOTE: HICON* */
539 DWORD w, /* [in] NOTE: 0 */
540 UINT nIcons,
541 DWORD y ) /* [in] NOTE: 0x80 maybe LR_* constant */
543 DWORD ret;
544 TRACE("%s 0x%08x 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx\n",
545 debugstr_w(lpwstrFile),nIndex, sizeX ,sizeY ,phicon,w,nIcons,y );
547 if ((nIcons == 2) && HIWORD(sizeX) && HIWORD(sizeY))
549 ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, 1, sizeX & 0xffff, sizeY & 0xffff );
550 if (!SUCCEEDED(ret)) return ret;
551 ret = ICO_ExtractIconExW(lpwstrFile, phicon+1, nIndex, 1, (sizeX>>16) & 0xffff, (sizeY>>16) & 0xffff );
552 } else
553 ret = ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX & 0xffff, sizeY & 0xffff );
554 return ret;
557 /***********************************************************************
558 * PrivateExtractIconsA [USER32.@]
561 HRESULT WINAPI PrivateExtractIconsA (
562 LPCSTR lpstrFile,
563 INT nIndex,
564 DWORD sizeX,
565 DWORD sizeY,
566 HICON * phicon,
567 DWORD w, /* [in] NOTE: 0 */
568 UINT nIcons,
569 DWORD y ) /* [in] NOTE: 0x80 */
571 DWORD ret;
572 LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
574 ret = PrivateExtractIconsW(
575 lpwstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y
578 HeapFree(GetProcessHeap(), 0, lpwstrFile);
579 return ret;
582 /***********************************************************************
583 * PrivateExtractIconExW [USER32.443]
584 * NOTES
585 * if nIcons = -1 it returns the number of icons in any case !!!
587 HRESULT WINAPI PrivateExtractIconExW (
588 LPCWSTR lpwstrFile,
589 DWORD nIndex,
590 HICON * phIconLarge,
591 HICON * phIconSmall,
592 UINT nIcons )
594 DWORD cyicon, cysmicon, cxicon, cxsmicon;
595 HRESULT ret = 0;
597 TRACE("%s 0x%08lx %p %p 0x%08x\n",
598 debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
600 if (nIndex == 1 && phIconSmall && phIconLarge)
602 HICON hIcon[2];
603 cxicon = GetSystemMetrics(SM_CXICON);
604 cyicon = GetSystemMetrics(SM_CYICON);
605 cxsmicon = GetSystemMetrics(SM_CXSMICON);
606 cysmicon = GetSystemMetrics(SM_CYSMICON);
608 ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon | (cxsmicon<<16), cyicon | (cysmicon<<16),
609 (HICON*) &hIcon, 0, 2, 0 );
610 *phIconLarge = hIcon[0];
611 *phIconSmall = hIcon[1];
612 return ret;
615 if (nIndex != -1)
617 if (phIconSmall)
619 /* extract n small icons */
620 cxsmicon = GetSystemMetrics(SM_CXSMICON);
621 cysmicon = GetSystemMetrics(SM_CYSMICON);
622 ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxsmicon, cysmicon, phIconSmall, 0, nIcons, 0 );
624 if (phIconLarge )
626 /* extract n large icons */
627 cxicon = GetSystemMetrics(SM_CXICON);
628 cyicon = GetSystemMetrics(SM_CYICON);
629 ret = PrivateExtractIconsW ( lpwstrFile, nIndex, cxicon, cyicon, phIconLarge, 0, nIcons, 0 );
631 return ret;
634 /* get the number of icons */
635 return PrivateExtractIconsW ( lpwstrFile, 0, 0, 0, 0, 0, 0, 0 );
638 /***********************************************************************
639 * PrivateExtractIconExA [USER32.442]
641 HRESULT WINAPI PrivateExtractIconExA (
642 LPCSTR lpstrFile,
643 DWORD nIndex,
644 HICON * phIconLarge,
645 HICON * phIconSmall,
646 UINT nIcons )
648 DWORD ret;
649 LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
651 TRACE("%s 0x%08lx %p %p 0x%08x\n",
652 lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
654 ret = PrivateExtractIconExW(lpwstrFile,nIndex,phIconLarge, phIconSmall, nIcons);
656 HeapFree(GetProcessHeap(), 0, lpwstrFile);
657 return ret;