comctl32/tests: Use CRT allocation functions.
[wine.git] / dlls / user32 / exticon.c
blob415bb9864b819c1393846ac14e8fb9962decb1c3
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
8 * Copyright 2000 Juergen Schmied
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <stdlib.h>
26 #include "user_private.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(icon);
31 #include "pshpack1.h"
33 typedef struct
35 BYTE bWidth; /* Width, in pixels, of the image */
36 BYTE bHeight; /* Height, in pixels, of the image */
37 BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
38 BYTE bReserved; /* Reserved ( must be 0) */
39 WORD wPlanes; /* Color Planes */
40 WORD wBitCount; /* Bits per pixel */
41 DWORD dwBytesInRes; /* How many bytes in this resource? */
42 DWORD dwImageOffset; /* Where in the file is this image? */
43 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
45 typedef struct
47 WORD idReserved; /* Reserved (must be 0) */
48 WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
49 WORD idCount; /* How many images */
50 icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
51 } icoICONDIR, *LPicoICONDIR;
53 typedef struct
55 WORD offset;
56 WORD length;
57 WORD flags;
58 WORD id;
59 WORD handle;
60 WORD usage;
61 } NE_NAMEINFO;
63 typedef struct
65 WORD type_id;
66 WORD count;
67 DWORD resloader;
68 } NE_TYPEINFO;
70 #define NE_RSCTYPE_ICON 0x8003
71 #define NE_RSCTYPE_GROUP_ICON 0x800e
73 #include "poppack.h"
75 #if 0
76 static void dumpIcoDirEntry ( LPicoICONDIRENTRY entry )
78 TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
79 TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
80 TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
81 entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
83 static void dumpIcoDir ( LPicoICONDIR entry )
85 TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
87 #endif
89 /**********************************************************************
90 * find_entry_by_id
92 * Find an entry by id 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_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
96 WORD id, const void *root )
98 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
99 int min, max, pos;
101 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
102 min = dir->NumberOfNamedEntries;
103 max = min + dir->NumberOfIdEntries - 1;
104 while (min <= max)
106 pos = (min + max) / 2;
107 if (entry[pos].Id == id)
108 return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].OffsetToDirectory);
109 if (entry[pos].Id > id) max = pos - 1;
110 else min = pos + 1;
112 return NULL;
115 /**********************************************************************
116 * find_entry_default
118 * Find a default entry in a resource directory
119 * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
121 static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
122 const void *root )
124 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
125 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
126 return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry->OffsetToDirectory);
129 /*************************************************************************
130 * USER32_GetResourceTable
132 static DWORD USER32_GetResourceTable(LPBYTE peimage,DWORD pesize,LPBYTE *retptr)
134 IMAGE_DOS_HEADER * mz_header;
136 TRACE("%p %p\n", peimage, retptr);
138 *retptr = NULL;
140 mz_header = (IMAGE_DOS_HEADER*) peimage;
142 if (mz_header->e_magic != IMAGE_DOS_SIGNATURE)
144 if (mz_header->e_cblp == 1) /* .ICO file ? */
146 *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
147 return 1;
149 else
150 return 0; /* failed */
152 if (mz_header->e_lfanew >= pesize) {
153 return 0; /* failed, happens with PKZIP DOS Exes for instance. */
155 if (*((DWORD*)(peimage + mz_header->e_lfanew)) == IMAGE_NT_SIGNATURE )
156 return IMAGE_NT_SIGNATURE;
158 if (*((WORD*)(peimage + mz_header->e_lfanew)) == IMAGE_OS2_SIGNATURE )
160 IMAGE_OS2_HEADER * ne_header;
162 ne_header = (IMAGE_OS2_HEADER*)(peimage + mz_header->e_lfanew);
164 if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE)
165 return 0;
167 if( (ne_header->ne_restab - ne_header->ne_rsrctab) <= sizeof(NE_TYPEINFO) )
168 *retptr = (LPBYTE)-1;
169 else
170 *retptr = peimage + mz_header->e_lfanew + ne_header->ne_rsrctab;
172 return IMAGE_OS2_SIGNATURE;
174 return 0; /* failed */
176 /*************************************************************************
177 * USER32_LoadResource
179 static BYTE * USER32_LoadResource( LPBYTE peimage, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
181 TRACE("%p %p 0x%08x\n", peimage, pNInfo, sizeShift);
183 *uSize = (DWORD)pNInfo->length << sizeShift;
184 return peimage + ((DWORD)pNInfo->offset << sizeShift);
187 /*************************************************************************
188 * ICO_LoadIcon
190 static BYTE * ICO_LoadIcon( LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
192 TRACE("%p %p\n", peimage, lpiIDE);
194 *uSize = lpiIDE->dwBytesInRes;
195 return peimage + lpiIDE->dwImageOffset;
198 /*************************************************************************
199 * ICO_GetIconDirectory
201 * Reads .ico file and build phony ICONDIR struct
203 static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG *uSize )
205 CURSORICONFILEDIR *lpcid; /* icon resource in resource-dir format */
206 CURSORICONDIR * lpID; /* icon resource in resource format */
207 int i;
209 TRACE("%p %p\n", peimage, lplpiID);
211 lpcid = (CURSORICONFILEDIR*)peimage;
213 if( lpcid->idReserved || (lpcid->idType != 1) || (!lpcid->idCount) )
214 return 0;
216 /* allocate the phony ICONDIR structure */
217 *uSize = FIELD_OFFSET(CURSORICONDIR, idEntries[lpcid->idCount]);
218 if( (lpID = HeapAlloc(GetProcessHeap(),0, *uSize) ))
220 /* copy the header */
221 lpID->idReserved = lpcid->idReserved;
222 lpID->idType = lpcid->idType;
223 lpID->idCount = lpcid->idCount;
225 /* copy the entries */
226 for( i=0; i < lpcid->idCount; i++ )
228 memcpy(&lpID->idEntries[i], &lpcid->idEntries[i], sizeof(CURSORICONDIRENTRY) - 2);
229 lpID->idEntries[i].wResId = i;
232 *lplpiID = (LPicoICONDIR)peimage;
233 return (BYTE *)lpID;
235 return 0;
238 /*************************************************************************
239 * ICO_ExtractIconExW [internal]
241 * NOTES
242 * nIcons = 0: returns number of Icons in file
244 * returns
245 * invalid file: -1
246 * failure:0;
247 * success: number of icons in file (nIcons = 0) or nr of icons retrieved
249 static UINT ICO_ExtractIconExW(
250 LPCWSTR lpszExeFileName,
251 HICON * RetPtr,
252 INT nIconIndex,
253 UINT nIcons,
254 UINT cxDesired,
255 UINT cyDesired,
256 UINT *pIconId,
257 UINT flags)
259 UINT ret = 0;
260 UINT cx1, cx2, cy1, cy2;
261 LPBYTE pData;
262 DWORD sig;
263 HANDLE hFile;
264 UINT16 iconDirCount = 0,iconCount = 0;
265 LPBYTE peimage;
266 HANDLE fmapping;
267 DWORD fsizeh,fsizel;
268 WCHAR szExePath[MAX_PATH];
269 DWORD dwSearchReturn;
271 TRACE("%s, %d, %d %p 0x%08x\n", debugstr_w(lpszExeFileName), nIconIndex, nIcons, pIconId, flags);
273 dwSearchReturn = SearchPathW(NULL, lpszExeFileName, NULL, ARRAY_SIZE(szExePath), szExePath, NULL);
274 if ((dwSearchReturn == 0) || (dwSearchReturn > ARRAY_SIZE(szExePath)))
276 WARN("File %s not found or path too long\n", debugstr_w(lpszExeFileName));
277 return -1;
280 hFile = CreateFileW(szExePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
281 if (hFile == INVALID_HANDLE_VALUE) return ret;
282 fsizel = GetFileSize(hFile,&fsizeh);
284 /* Map the file */
285 fmapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
286 CloseHandle(hFile);
287 if (!fmapping)
289 WARN("CreateFileMapping error %ld\n", GetLastError() );
290 return 0xFFFFFFFF;
293 if (!(peimage = MapViewOfFile(fmapping, FILE_MAP_READ, 0, 0, 0)))
295 WARN("MapViewOfFile error %ld\n", GetLastError() );
296 CloseHandle(fmapping);
297 return 0xFFFFFFFF;
299 CloseHandle(fmapping);
301 cx1 = LOWORD(cxDesired);
302 cx2 = HIWORD(cxDesired);
303 cy1 = LOWORD(cyDesired);
304 cy2 = HIWORD(cyDesired);
306 if (pIconId) /* Invalidate first icon identifier */
307 *pIconId = 0xFFFFFFFF;
309 if (!pIconId) /* if no icon identifier array present use the icon handle array as intermediate storage */
310 pIconId = (UINT*)RetPtr;
312 sig = USER32_GetResourceTable(peimage, fsizel, &pData);
314 /* ico file or NE exe/dll*/
315 if (sig==IMAGE_OS2_SIGNATURE || sig==1) /* .ICO file */
317 BYTE *pCIDir = 0;
318 NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
319 NE_NAMEINFO *pIconStorage = NULL;
320 NE_NAMEINFO *pIconDir = NULL;
321 LPicoICONDIR lpiID = NULL;
322 ULONG uSize = 0;
324 TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
326 if (pData == (BYTE*)-1)
328 pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize); /* check for .ICO file */
329 if (pCIDir)
331 iconDirCount = 1; iconCount = lpiID->idCount;
332 TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
335 else while (pTInfo->type_id && !(pIconStorage && pIconDir))
337 if (pTInfo->type_id == NE_RSCTYPE_GROUP_ICON) /* find icon directory and icon repository */
339 iconDirCount = pTInfo->count;
340 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
341 TRACE("\tfound directory - %i icon families\n", iconDirCount);
343 if (pTInfo->type_id == NE_RSCTYPE_ICON)
345 iconCount = pTInfo->count;
346 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
347 TRACE("\ttotal icons - %i\n", iconCount);
349 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
352 if ((pIconStorage && pIconDir) || lpiID) /* load resources and create icons */
354 if (nIcons == 0)
356 ret = iconDirCount;
357 if (lpiID) /* *.ico file, deallocate heap pointer*/
358 HeapFree(GetProcessHeap(), 0, pCIDir);
360 else if (nIconIndex < iconDirCount)
362 UINT16 i, icon;
363 if (nIcons > iconDirCount - nIconIndex)
364 nIcons = iconDirCount - nIconIndex;
366 for (i = 0; i < nIcons; i++)
368 /* .ICO files have only one icon directory */
369 if (lpiID == NULL) /* not *.ico */
370 pCIDir = USER32_LoadResource(peimage, pIconDir + i + nIconIndex, *(WORD*)pData, &uSize);
371 pIconId[i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, cx1, cy1, flags);
372 if (cx2 && cy2) pIconId[++i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, cx2, cy2, flags);
374 if (lpiID) /* *.ico file, deallocate heap pointer*/
375 HeapFree(GetProcessHeap(), 0, pCIDir);
377 for (icon = 0; icon < nIcons; icon++)
379 pCIDir = NULL;
380 if (lpiID)
381 pCIDir = ICO_LoadIcon(peimage, lpiID->idEntries + (int)pIconId[icon], &uSize);
382 else
383 for (i = 0; i < iconCount; i++)
384 if (pIconStorage[i].id == ((int)pIconId[icon] | 0x8000) )
385 pCIDir = USER32_LoadResource(peimage, pIconStorage + i, *(WORD*)pData, &uSize);
387 if (pCIDir)
389 RetPtr[icon] = CreateIconFromResourceEx(pCIDir, uSize, TRUE, 0x00030000,
390 cx1, cy1, flags);
391 if (cx2 && cy2)
392 RetPtr[++icon] = CreateIconFromResourceEx(pCIDir, uSize, TRUE, 0x00030000,
393 cx2, cy2, flags);
395 else
396 RetPtr[icon] = 0;
398 ret = icon; /* return number of retrieved icons */
402 /* end ico file */
404 /* exe/dll */
405 else if( sig == IMAGE_NT_SIGNATURE )
407 BYTE *idata, *igdata;
408 const IMAGE_RESOURCE_DIRECTORY *rootresdir, *iconresdir, *icongroupresdir;
409 const IMAGE_RESOURCE_DATA_ENTRY *idataent, *igdataent;
410 const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
411 ULONG size;
412 UINT i;
414 rootresdir = RtlImageDirectoryEntryToData((HMODULE)peimage, FALSE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &size);
415 if (!rootresdir)
417 WARN("haven't found section for resource directory.\n");
418 goto end;
421 /* search for the group icon directory */
422 if (!(icongroupresdir = find_entry_by_id(rootresdir, LOWORD(RT_GROUP_ICON), rootresdir)))
424 WARN("No Icongroupresourcedirectory!\n");
425 goto end; /* failure */
427 iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
429 /* only number of icons requested */
430 if( !pIconId )
432 ret = iconDirCount;
433 goto end; /* success */
436 if( nIconIndex < 0 )
438 /* search resource id */
439 int n = 0;
440 int iId = abs(nIconIndex);
441 const IMAGE_RESOURCE_DIRECTORY_ENTRY* xprdeTmp = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1);
443 while(n<iconDirCount && xprdeTmp)
445 if(xprdeTmp->Id == iId)
447 nIconIndex = n;
448 break;
450 n++;
451 xprdeTmp++;
453 if (nIconIndex < 0)
455 WARN("resource id %d not found\n", iId);
456 goto end; /* failure */
459 else
461 /* check nIconIndex to be in range */
462 if (nIconIndex >= iconDirCount)
464 WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
465 goto end; /* failure */
469 /* assure we don't get too much */
470 if( nIcons > iconDirCount - nIconIndex )
471 nIcons = iconDirCount - nIconIndex;
473 /* starting from specified index */
474 xresent = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1) + nIconIndex;
476 for (i=0; i < nIcons; i++,xresent++)
478 const IMAGE_RESOURCE_DIRECTORY *resdir;
480 /* go down this resource entry, name */
481 resdir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)rootresdir + xresent->OffsetToDirectory);
483 /* default language (0) */
484 resdir = find_entry_default(resdir,rootresdir);
485 igdataent = (const IMAGE_RESOURCE_DATA_ENTRY*)resdir;
487 /* lookup address in mapped image for virtual address */
488 igdata = RtlImageRvaToVa(RtlImageNtHeader((HMODULE)peimage), (HMODULE)peimage, igdataent->OffsetToData, NULL);
489 if (!igdata)
491 FIXME("no matching real address for icongroup!\n");
492 goto end; /* failure */
494 pIconId[i] = LookupIconIdFromDirectoryEx(igdata, TRUE, cx1, cy1, flags);
495 if (cx2 && cy2) pIconId[++i] = LookupIconIdFromDirectoryEx(igdata, TRUE, cx2, cy2, flags);
498 if (!(iconresdir=find_entry_by_id(rootresdir,LOWORD(RT_ICON),rootresdir)))
500 WARN("No Iconresourcedirectory!\n");
501 goto end; /* failure */
504 for (i=0; i<nIcons; i++)
506 const IMAGE_RESOURCE_DIRECTORY *xresdir;
507 xresdir = find_entry_by_id(iconresdir, LOWORD(pIconId[i]), rootresdir);
508 if( !xresdir )
510 WARN("icon entry %d not found\n", LOWORD(pIconId[i]));
511 RetPtr[i]=0;
512 continue;
514 xresdir = find_entry_default(xresdir, rootresdir);
515 idataent = (const IMAGE_RESOURCE_DATA_ENTRY*)xresdir;
517 idata = RtlImageRvaToVa(RtlImageNtHeader((HMODULE)peimage), (HMODULE)peimage, idataent->OffsetToData, NULL);
518 if (!idata)
520 WARN("no matching real address found for icondata!\n");
521 RetPtr[i]=0;
522 continue;
524 RetPtr[i] = CreateIconFromResourceEx(idata, idataent->Size, TRUE, 0x00030000, cx1, cy1, flags);
525 if (cx2 && cy2)
526 RetPtr[++i] = CreateIconFromResourceEx(idata, idataent->Size, TRUE, 0x00030000, cx2, cy2, flags);
528 ret = i; /* return number of retrieved icons */
529 } /* if(sig == IMAGE_NT_SIGNATURE) */
531 end:
532 UnmapViewOfFile(peimage); /* success */
533 return ret;
536 /***********************************************************************
537 * PrivateExtractIconsW [USER32.@]
539 * NOTES
540 * If HIWORD(sizeX) && HIWORD(sizeY) 2 * ((nIcons + 1) MOD 2) icons are
541 * returned, with the LOWORD size icon first and the HIWORD size icon
542 * second.
543 * Also the Windows equivalent does extract icons in a strange way if
544 * nIndex is negative. Our implementation treats a negative nIndex as
545 * looking for that resource identifier for the first icon to retrieve.
547 * FIXME:
548 * should also support 16 bit EXE + DLLs, cursor and animated cursor as
549 * well as bitmap files.
552 UINT WINAPI PrivateExtractIconsW (
553 LPCWSTR lpwstrFile,
554 int nIndex,
555 int sizeX,
556 int sizeY,
557 HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
558 UINT* pIconId, /* [out] pointer to array of nIcons icon identifiers or NULL */
559 UINT nIcons, /* [in] number of icons to retrieve */
560 UINT flags ) /* [in] LR_* flags used by LoadImage */
562 TRACE("%s %d %dx%d %p %p %d 0x%08x\n",
563 debugstr_w(lpwstrFile), nIndex, sizeX, sizeY, phicon, pIconId, nIcons, flags);
565 if ((nIcons & 1) && HIWORD(sizeX) && HIWORD(sizeY))
567 WARN("Uneven number %d of icons requested for small and large icons!\n", nIcons);
569 return ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX, sizeY, pIconId, flags);
572 /***********************************************************************
573 * PrivateExtractIconsA [USER32.@]
576 UINT WINAPI PrivateExtractIconsA (
577 LPCSTR lpstrFile,
578 int nIndex,
579 int sizeX,
580 int sizeY,
581 HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
582 UINT* piconid, /* [out] pointer to array of nIcons icon identifiers or NULL */
583 UINT nIcons, /* [in] number of icons to retrieve */
584 UINT flags ) /* [in] LR_* flags used by LoadImage */
586 UINT ret;
587 INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
588 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
590 MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
591 ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, piconid, nIcons, flags);
593 HeapFree(GetProcessHeap(), 0, lpwstrFile);
594 return ret;
597 /***********************************************************************
598 * PrivateExtractIconExW [USER32.@]
599 * NOTES
600 * if nIndex == -1 it returns the number of icons in any case !!!
602 UINT WINAPI PrivateExtractIconExW (
603 LPCWSTR lpwstrFile,
604 int nIndex,
605 HICON * phIconLarge,
606 HICON * phIconSmall,
607 UINT nIcons )
609 DWORD cyicon, cysmicon, cxicon, cxsmicon;
610 UINT ret = 0;
612 TRACE("%s %d %p %p %d\n",
613 debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
615 if (nIndex == -1)
616 /* get the number of icons */
617 return ICO_ExtractIconExW(lpwstrFile, NULL, 0, 0, 0, 0, NULL, LR_DEFAULTCOLOR);
619 if (nIcons == 1 && phIconSmall && phIconLarge)
621 HICON hIcon[2];
622 cxicon = GetSystemMetrics(SM_CXICON);
623 cyicon = GetSystemMetrics(SM_CYICON);
624 cxsmicon = GetSystemMetrics(SM_CXSMICON);
625 cysmicon = GetSystemMetrics(SM_CYSMICON);
627 ret = ICO_ExtractIconExW(lpwstrFile, hIcon, nIndex, 2, cxicon | (cxsmicon<<16),
628 cyicon | (cysmicon<<16), NULL, LR_DEFAULTCOLOR);
629 *phIconLarge = hIcon[0];
630 *phIconSmall = hIcon[1];
631 return ret;
634 if (phIconSmall)
636 /* extract n small icons */
637 cxsmicon = GetSystemMetrics(SM_CXSMICON);
638 cysmicon = GetSystemMetrics(SM_CYSMICON);
639 ret = ICO_ExtractIconExW(lpwstrFile, phIconSmall, nIndex, nIcons, cxsmicon,
640 cysmicon, NULL, LR_DEFAULTCOLOR);
642 if (phIconLarge)
644 /* extract n large icons */
645 cxicon = GetSystemMetrics(SM_CXICON);
646 cyicon = GetSystemMetrics(SM_CYICON);
647 ret = ICO_ExtractIconExW(lpwstrFile, phIconLarge, nIndex, nIcons, cxicon,
648 cyicon, NULL, LR_DEFAULTCOLOR);
650 return ret;
653 /***********************************************************************
654 * PrivateExtractIconExA [USER32.@]
656 UINT WINAPI PrivateExtractIconExA (
657 LPCSTR lpstrFile,
658 int nIndex,
659 HICON * phIconLarge,
660 HICON * phIconSmall,
661 UINT nIcons )
663 UINT ret;
664 INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
665 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
667 TRACE("%s %d %p %p %d\n", lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
669 MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
670 ret = PrivateExtractIconExW(lpwstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
671 HeapFree(GetProcessHeap(), 0, lpwstrFile);
672 return ret;