ReactOS  r76032
exticon.c
Go to the documentation of this file.
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  * Copyright 2000 Juergen Schmied
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 #include <user32.h>
26 
27 #include <wine/debug.h>
28 
29 /* Start of Hack section */
30 
32 
33 #include <pshpack1.h>
34 
35 typedef struct
36 {
37  BYTE bWidth; /* Width, in pixels, of the image */
38  BYTE bHeight; /* Height, in pixels, of the image */
39  BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
40  BYTE bReserved; /* Reserved ( must be 0) */
41  WORD wPlanes; /* Color Planes */
42  WORD wBitCount; /* Bits per pixel */
43  DWORD dwBytesInRes; /* How many bytes in this resource? */
44  DWORD dwImageOffset; /* Where in the file is this image? */
46 
47 typedef struct
48 {
49  WORD idReserved; /* Reserved (must be 0) */
50  WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
51  WORD idCount; /* How many images */
52  icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
54 
55 typedef struct
56 {
57  WORD offset;
58  WORD length;
59  WORD flags;
60  WORD id;
61  WORD handle;
62  WORD usage;
63 } NE_NAMEINFO;
64 
65 typedef struct
66 {
67  WORD type_id;
68  WORD count;
69  DWORD resloader;
70 } NE_TYPEINFO;
71 
72 #define NE_RSCTYPE_ICON 0x8003
73 #define NE_RSCTYPE_GROUP_ICON 0x800e
74 
75 #include <poppack.h>
76 
77 #if 0
78 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
79 {
80  TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
81  TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
82  TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
83  entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
84 }
85 static void dumpIcoDir ( LPicoICONDIR entry )
86 {
87  TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
88 }
89 #endif
90 
91 #ifndef WINE
94  int cxDesired,
95  int cyDesired,
96  BOOL bIcon,
97  DWORD fuLoad,
98  POINT *ptHotSpot);
99 #endif
100 
101 /**********************************************************************
102  * find_entry_by_id
103  *
104  * Find an entry by id in a resource directory
105  * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
106  */
108  WORD id, const void *root )
109 {
111  int min, max, pos;
112 
113  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
114  min = dir->NumberOfNamedEntries;
115  max = min + dir->NumberOfIdEntries - 1;
116  while (min <= max)
117  {
118  pos = (min + max) / 2;
119  if (entry[pos].Id == id)
120  return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].OffsetToDirectory);
121  if (entry[pos].Id > id) max = pos - 1;
122  else min = pos + 1;
123  }
124  return NULL;
125 }
126 
127 /**********************************************************************
128  * find_entry_default
129  *
130  * Find a default entry in a resource directory
131  * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
132  */
134  const void *root )
135 {
137  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
138  return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry->OffsetToDirectory);
139 }
140 
141 /*************************************************************************
142  * USER32_GetResourceTable
143  */
144 static DWORD USER32_GetResourceTable(LPBYTE peimage,DWORD pesize,LPBYTE *retptr)
145 {
146  IMAGE_DOS_HEADER * mz_header;
147 
148  TRACE("%p %p\n", peimage, retptr);
149 
150  *retptr = NULL;
151 
152  mz_header = (IMAGE_DOS_HEADER*) peimage;
153 
154  if (mz_header->e_magic != IMAGE_DOS_SIGNATURE)
155  {
156  if (mz_header->e_cblp == 1 || mz_header->e_cblp == 2) /* .ICO or .CUR file ? */
157  {
158  *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
159  return mz_header->e_cblp;
160  }
161  else
162  return 0; /* failed */
163  }
164  if (mz_header->e_lfanew >= pesize) {
165  return 0; /* failed, happens with PKZIP DOS Exes for instance. */
166  }
167  if (*((DWORD*)(peimage + mz_header->e_lfanew)) == IMAGE_NT_SIGNATURE )
168  return IMAGE_NT_SIGNATURE;
169 
170  if (*((WORD*)(peimage + mz_header->e_lfanew)) == IMAGE_OS2_SIGNATURE )
171  {
172  IMAGE_OS2_HEADER * ne_header;
173 
174  ne_header = (IMAGE_OS2_HEADER*)(peimage + mz_header->e_lfanew);
175 
176  if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE)
177  return 0;
178 
179  if( (ne_header->ne_restab - ne_header->ne_rsrctab) <= sizeof(NE_TYPEINFO) )
180  *retptr = (LPBYTE)-1;
181  else
182  *retptr = peimage + mz_header->e_lfanew + ne_header->ne_rsrctab;
183 
184  return IMAGE_OS2_SIGNATURE;
185  }
186  return 0; /* failed */
187 }
188 /*************************************************************************
189  * USER32_LoadResource
190  */
191 static BYTE * USER32_LoadResource( LPBYTE peimage, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
192 {
193  TRACE("%p %p 0x%08x\n", peimage, pNInfo, sizeShift);
194 
195  *uSize = (DWORD)pNInfo->length << sizeShift;
196  return peimage + ((DWORD)pNInfo->offset << sizeShift);
197 }
198 
199 /*************************************************************************
200  * ICO_LoadIcon
201  */
202 static BYTE * ICO_LoadIcon( LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
203 {
204  TRACE("%p %p\n", peimage, lpiIDE);
205 
206  *uSize = lpiIDE->dwBytesInRes;
207  return peimage + lpiIDE->dwImageOffset;
208 }
209 
210 /*************************************************************************
211  * ICO_GetIconDirectory
212  *
213  * Reads .ico file and build phony ICONDIR struct
214  */
215 static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG *uSize )
216 {
217  CURSORICONDIR * lpcid; /* icon resource in resource-dir format */
218  CURSORICONDIR * lpID; /* icon resource in resource format */
219  int i;
220 
221  TRACE("%p %p\n", peimage, lplpiID);
222 
223  lpcid = (CURSORICONDIR*)peimage;
224 
225  if( lpcid->idReserved || (lpcid->idType != 1) || (!lpcid->idCount) )
226  return 0;
227 
228  /* allocate the phony ICONDIR structure */
229  *uSize = FIELD_OFFSET(CURSORICONDIR, idEntries[lpcid->idCount]);
230  if( (lpID = HeapAlloc(GetProcessHeap(),0, *uSize) ))
231  {
232  /* copy the header */
233  lpID->idReserved = lpcid->idReserved;
234  lpID->idType = lpcid->idType;
235  lpID->idCount = lpcid->idCount;
236 
237  /* copy the entries */
238  for( i=0; i < lpcid->idCount; i++ )
239  {
240  memcpy(&lpID->idEntries[i], &lpcid->idEntries[i], sizeof(CURSORICONDIRENTRY) - 2);
241  lpID->idEntries[i].wResId = i;
242  }
243 
244  *lplpiID = (LPicoICONDIR)peimage;
245  return (BYTE *)lpID;
246  }
247  return 0;
248 }
249 
250 /*************************************************************************
251  * ICO_ExtractIconExW [internal]
252  *
253  * NOTES
254  * nIcons = 0: returns number of Icons in file
255  *
256  * returns
257  * invalid file: -1
258  * failure:0;
259  * success: number of icons in file (nIcons = 0) or nr of icons retrieved
260  */
262  LPCWSTR lpszExeFileName,
263  HICON * RetPtr,
264  INT nIconIndex,
265  UINT nIcons,
266  UINT cxDesired,
267  UINT cyDesired,
268  UINT *pIconId,
269  UINT flags)
270 {
271  UINT ret = 0;
272  UINT cx1, cx2, cy1, cy2;
273  LPBYTE pData;
274  DWORD sig;
275  HANDLE hFile;
276  UINT16 iconDirCount = 0,iconCount = 0;
277  LPBYTE peimage;
278  HANDLE fmapping;
279  DWORD fsizeh,fsizel;
280  WCHAR szExePath[MAX_PATH];
281  DWORD dwSearchReturn;
282 
283  TRACE("%s, %d, %d %p 0x%08x\n", debugstr_w(lpszExeFileName), nIconIndex, nIcons, pIconId, flags);
284 
285  dwSearchReturn = SearchPathW(NULL, lpszExeFileName, NULL, sizeof(szExePath) / sizeof(szExePath[0]), szExePath, NULL);
286  if ((dwSearchReturn == 0) || (dwSearchReturn > sizeof(szExePath) / sizeof(szExePath[0])))
287  {
288  WARN("File %s not found or path too long\n", debugstr_w(lpszExeFileName));
289  return -1;
290  }
291 
292  hFile = CreateFileW(szExePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
293  if (hFile == INVALID_HANDLE_VALUE) return ret;
294  fsizel = GetFileSize(hFile,&fsizeh);
295 
296  /* Map the file */
297  fmapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
298  CloseHandle(hFile);
299  if (!fmapping)
300  {
301  WARN("CreateFileMapping error %ld\n", GetLastError() );
302  return 0xFFFFFFFF;
303  }
304 
305  if (!(peimage = MapViewOfFile(fmapping, FILE_MAP_READ, 0, 0, 0)))
306  {
307  WARN("MapViewOfFile error %ld\n", GetLastError() );
308  CloseHandle(fmapping);
309  return 0xFFFFFFFF;
310  }
311  CloseHandle(fmapping);
312 
313  cx1 = LOWORD(cxDesired);
314  cx2 = HIWORD(cxDesired);
315  cy1 = LOWORD(cyDesired);
316  cy2 = HIWORD(cyDesired);
317 
318  if (pIconId) /* Invalidate first icon identifier */
319  *pIconId = 0xFFFFFFFF;
320 
321  if (!pIconId) /* if no icon identifier array present use the icon handle array as intermediate storage */
322  pIconId = (UINT*)RetPtr;
323 
324  sig = USER32_GetResourceTable(peimage, fsizel, &pData);
325 
326 /* NE exe/dll */
327  if (sig==IMAGE_OS2_SIGNATURE)
328  {
329  BYTE *pCIDir = 0;
330  NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
331  NE_NAMEINFO *pIconStorage = NULL;
332  NE_NAMEINFO *pIconDir = NULL;
333  LPicoICONDIR lpiID = NULL;
334  ULONG uSize = 0;
335 
336  TRACE("-- OS2/icon Signature (0x%08x)\n", sig);
337 
338  if (pData == (BYTE*)-1)
339  {
340  pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize); /* check for .ICO file */
341  if (pCIDir)
342  {
343  iconDirCount = 1; iconCount = lpiID->idCount;
344  TRACE("-- icon found %p 0x%08x 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
345  }
346  }
347  else while (pTInfo->type_id && !(pIconStorage && pIconDir))
348  {
349  if (pTInfo->type_id == NE_RSCTYPE_GROUP_ICON) /* find icon directory and icon repository */
350  {
351  iconDirCount = pTInfo->count;
352  pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
353  TRACE("\tfound directory - %i icon families\n", iconDirCount);
354  }
355  if (pTInfo->type_id == NE_RSCTYPE_ICON)
356  {
357  iconCount = pTInfo->count;
358  pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
359  TRACE("\ttotal icons - %i\n", iconCount);
360  }
361  pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
362  }
363 
364  if ((pIconStorage && pIconDir) || lpiID) /* load resources and create icons */
365  {
366  if (nIcons == 0)
367  {
368  ret = iconDirCount;
369  if (lpiID) /* *.ico file, deallocate heap pointer*/
370  HeapFree(GetProcessHeap(), 0, pCIDir);
371  }
372  else if (nIconIndex < iconDirCount)
373  {
374  UINT16 i, icon;
375  if (nIcons > iconDirCount - nIconIndex)
376  nIcons = iconDirCount - nIconIndex;
377 
378  for (i = 0; i < nIcons; i++)
379  {
380  /* .ICO files have only one icon directory */
381  if (lpiID == NULL) /* not *.ico */
382  pCIDir = USER32_LoadResource(peimage, pIconDir + i + nIconIndex, *(WORD*)pData, &uSize);
383  pIconId[i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, cx1, cy1, flags);
384  if (cx2 && cy2) pIconId[++i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, cx2, cy2, flags);
385  }
386  if (lpiID) /* *.ico file, deallocate heap pointer*/
387  HeapFree(GetProcessHeap(), 0, pCIDir);
388 
389  for (icon = 0; icon < nIcons; icon++)
390  {
391  pCIDir = NULL;
392  if (lpiID)
393  pCIDir = ICO_LoadIcon(peimage, lpiID->idEntries + (int)pIconId[icon], &uSize);
394  else
395  for (i = 0; i < iconCount; i++)
396  if (pIconStorage[i].id == ((int)pIconId[icon] | 0x8000) )
397  pCIDir = USER32_LoadResource(peimage, pIconStorage + i, *(WORD*)pData, &uSize);
398 
399  if (pCIDir)
400  {
401  RetPtr[icon] = CreateIconFromResourceEx(pCIDir, uSize, TRUE, 0x00030000,
402  cx1, cy1, flags);
403  if (cx2 && cy2)
404  RetPtr[++icon] = CreateIconFromResourceEx(pCIDir, uSize, TRUE, 0x00030000,
405  cx2, cy2, flags);
406  }
407  else
408  RetPtr[icon] = 0;
409  }
410  ret = icon; /* return number of retrieved icons */
411  }
412  }
413  }
414  else
415  if (sig == 1 || sig == 2) /* .ICO or .CUR file */
416  {
417  TRACE("-- icon Signature (0x%08x)\n", sig);
418 
419  if (pData == (BYTE*)-1)
420  {
421  INT cx[2] = {cx1, cx2}, cy[2] = {cy1, cy2};
422  INT index;
423 
424  for(index = 0; index < (cx2 || cy2 ? 2 : 1); index++)
425  {
426  DWORD dataOffset;
427  LPBYTE imageData;
428  POINT hotSpot;
430 
431  dataOffset = get_best_icon_file_offset(peimage, fsizel, cx[index], cy[index], sig == 1, flags, sig == 1 ? NULL : &hotSpot);
432 
433  if (dataOffset)
434  {
435  HICON icon;
436  WORD *cursorData = NULL;
437 
438  imageData = peimage + dataOffset;
439  entry = (LPICONIMAGE)(imageData);
440 
441  if(sig == 2)
442  {
443  /* we need to prepend the bitmap data with hot spots for CreateIconFromResourceEx */
444  cursorData = HeapAlloc(GetProcessHeap(), 0, entry->icHeader.biSizeImage + 2 * sizeof(WORD));
445 
446  if(!cursorData)
447  continue;
448 
449  cursorData[0] = hotSpot.x;
450  cursorData[1] = hotSpot.y;
451 
452  memcpy(cursorData + 2, imageData, entry->icHeader.biSizeImage);
453 
454  imageData = (LPBYTE)cursorData;
455  }
456 
457  icon = CreateIconFromResourceEx(imageData, entry->icHeader.biSizeImage, sig == 1, 0x00030000, cx[index], cy[index], flags);
458 
459  if (icon)
460  {
461  RetPtr[index] = icon;
462  iconCount = 1;
463  }
464 
465  if(cursorData != NULL)
466  HeapFree(GetProcessHeap(), 0, cursorData);
467  }
468  }
469 
470  }
471  ret = iconCount; /* return number of retrieved icons */
472  }
473 /* end ico file */
474 
475 /* exe/dll */
476  else if( sig == IMAGE_NT_SIGNATURE )
477  {
478  BYTE *idata, *igdata;
479  const IMAGE_RESOURCE_DIRECTORY *rootresdir, *iconresdir, *icongroupresdir;
480  const IMAGE_RESOURCE_DATA_ENTRY *idataent, *igdataent;
481  const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
482  ULONG size;
483  UINT i;
484 
486  if (!rootresdir)
487  {
488  WARN("haven't found section for resource directory.\n");
489  goto end;
490  }
491 
492  /* search for the group icon directory */
493  if (!(icongroupresdir = find_entry_by_id(rootresdir, LOWORD(RT_GROUP_ICON), rootresdir)))
494  {
495  WARN("No Icongroupresourcedirectory!\n");
496  goto end; /* failure */
497  }
498  iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
499 
500  /* only number of icons requested */
501  if( !pIconId )
502  {
503  ret = iconDirCount;
504  goto end; /* success */
505  }
506 
507  if( nIconIndex < 0 )
508  {
509  /* search resource id */
510  int n = 0;
511  int iId = abs(nIconIndex);
512  const IMAGE_RESOURCE_DIRECTORY_ENTRY* xprdeTmp = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1);
513 
514  while(n<iconDirCount && xprdeTmp)
515  {
516  if(xprdeTmp->Id == iId)
517  {
518  nIconIndex = n;
519  break;
520  }
521  n++;
522  xprdeTmp++;
523  }
524  if (nIconIndex < 0)
525  {
526  WARN("resource id %d not found\n", iId);
527  goto end; /* failure */
528  }
529  }
530  else
531  {
532  /* check nIconIndex to be in range */
533  if (nIconIndex >= iconDirCount)
534  {
535  WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
536  goto end; /* failure */
537  }
538  }
539 
540  /* assure we don't get too much */
541  if( nIcons > iconDirCount - nIconIndex )
542  nIcons = iconDirCount - nIconIndex;
543 
544  /* starting from specified index */
545  xresent = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1) + nIconIndex;
546 
547  for (i=0; i < nIcons; i++,xresent++)
548  {
549  const IMAGE_RESOURCE_DIRECTORY *resdir;
550 
551  /* go down this resource entry, name */
552  resdir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)rootresdir + xresent->OffsetToDirectory);
553 
554  /* default language (0) */
555  resdir = find_entry_default(resdir,rootresdir);
556  igdataent = (const IMAGE_RESOURCE_DATA_ENTRY*)resdir;
557 
558  /* lookup address in mapped image for virtual address */
559  igdata = RtlImageRvaToVa(RtlImageNtHeader((HMODULE)peimage), (HMODULE)peimage, igdataent->OffsetToData, NULL);
560  if (!igdata)
561  {
562  FIXME("no matching real address for icongroup!\n");
563  goto end; /* failure */
564  }
565  pIconId[i] = LookupIconIdFromDirectoryEx(igdata, TRUE, cx1, cy1, flags);
566  if (cx2 && cy2) pIconId[++i] = LookupIconIdFromDirectoryEx(igdata, TRUE, cx2, cy2, flags);
567  }
568 
569  if (!(iconresdir=find_entry_by_id(rootresdir,LOWORD(RT_ICON),rootresdir)))
570  {
571  WARN("No Iconresourcedirectory!\n");
572  goto end; /* failure */
573  }
574 
575  for (i=0; i<nIcons; i++)
576  {
577  const IMAGE_RESOURCE_DIRECTORY *xresdir;
578  xresdir = find_entry_by_id(iconresdir, LOWORD(pIconId[i]), rootresdir);
579  if( !xresdir )
580  {
581  WARN("icon entry %d not found\n", LOWORD(pIconId[i]));
582  RetPtr[i]=0;
583  continue;
584  }
585  xresdir = find_entry_default(xresdir, rootresdir);
586  idataent = (const IMAGE_RESOURCE_DATA_ENTRY*)xresdir;
587 
588  idata = RtlImageRvaToVa(RtlImageNtHeader((HMODULE)peimage), (HMODULE)peimage, idataent->OffsetToData, NULL);
589  if (!idata)
590  {
591  WARN("no matching real address found for icondata!\n");
592  RetPtr[i]=0;
593  continue;
594  }
595  RetPtr[i] = CreateIconFromResourceEx(idata, idataent->Size, TRUE, 0x00030000, cx1, cy1, flags);
596  if (cx2 && cy2)
597  RetPtr[++i] = CreateIconFromResourceEx(idata, idataent->Size, TRUE, 0x00030000, cx2, cy2, flags);
598  }
599  ret = i; /* return number of retrieved icons */
600  } /* if(sig == IMAGE_NT_SIGNATURE) */
601 
602 end:
603  UnmapViewOfFile(peimage); /* success */
604  return ret;
605 }
606 
607 /***********************************************************************
608  * PrivateExtractIconsW [USER32.@]
609  *
610  * NOTES
611  * If HIWORD(sizeX) && HIWORD(sizeY) 2 * ((nIcons + 1) MOD 2) icons are
612  * returned, with the LOWORD size icon first and the HIWORD size icon
613  * second.
614  * Also the Windows equivalent does extract icons in a strange way if
615  * nIndex is negative. Our implementation treats a negative nIndex as
616  * looking for that resource identifier for the first icon to retrieve.
617  *
618  * FIXME:
619  * should also support 16 bit EXE + DLLs, cursor and animated cursor as
620  * well as bitmap files.
621  */
622 
624  LPCWSTR lpwstrFile,
625  int nIndex,
626  int sizeX,
627  int sizeY,
628  HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
629  UINT* pIconId, /* [out] pointer to array of nIcons icon identifiers or NULL */
630  UINT nIcons, /* [in] number of icons to retrieve */
631  UINT flags ) /* [in] LR_* flags used by LoadImage */
632 {
633  TRACE("%s %d %dx%d %p %p %d 0x%08x\n",
634  debugstr_w(lpwstrFile), nIndex, sizeX, sizeY, phicon, pIconId, nIcons, flags);
635 
636  if ((nIcons & 1) && HIWORD(sizeX) && HIWORD(sizeY))
637  {
638  WARN("Uneven number %d of icons requested for small and large icons!\n", nIcons);
639  }
640  return ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX, sizeY, pIconId, flags);
641 }
642 
643 /***********************************************************************
644  * PrivateExtractIconsA [USER32.@]
645  */
646 
648  LPCSTR lpstrFile,
649  int nIndex,
650  int sizeX,
651  int sizeY,
652  HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
653  UINT* piconid, /* [out] pointer to array of nIcons icon identifiers or NULL */
654  UINT nIcons, /* [in] number of icons to retrieve */
655  UINT flags ) /* [in] LR_* flags used by LoadImage */
656 {
657  UINT ret;
658  INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
659  LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
660 #ifdef __REACTOS__
661  if (lpwstrFile == NULL)
662  return 0;
663 #endif
664 
665  MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
666  ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, piconid, nIcons, flags);
667 
668  HeapFree(GetProcessHeap(), 0, lpwstrFile);
669  return ret;
670 }
671 
672 /***********************************************************************
673  * PrivateExtractIconExW [USER32.@]
674  * NOTES
675  * if nIndex == -1 it returns the number of icons in any case !!!
676  */
678  LPCWSTR lpwstrFile,
679  int nIndex,
680  HICON * phIconLarge,
681  HICON * phIconSmall,
682  UINT nIcons )
683 {
684  DWORD cyicon, cysmicon, cxicon, cxsmicon;
685  UINT ret = 0;
686 
687  TRACE("%s %d %p %p %d\n",
688  debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
689 
690  if (nIndex == -1)
691  /* get the number of icons */
692  return ICO_ExtractIconExW(lpwstrFile, NULL, 0, 0, 0, 0, NULL, LR_DEFAULTCOLOR);
693 
694  if (nIcons == 1 && phIconSmall && phIconLarge)
695  {
696  HICON hIcon[2];
697  cxicon = GetSystemMetrics(SM_CXICON);
698  cyicon = GetSystemMetrics(SM_CYICON);
699  cxsmicon = GetSystemMetrics(SM_CXSMICON);
700  cysmicon = GetSystemMetrics(SM_CYSMICON);
701 
702  ret = ICO_ExtractIconExW(lpwstrFile, hIcon, nIndex, 2, cxicon | (cxsmicon<<16),
703  cyicon | (cysmicon<<16), NULL, LR_DEFAULTCOLOR);
704  *phIconLarge = hIcon[0];
705  *phIconSmall = hIcon[1];
706  return ret;
707  }
708 
709  if (phIconSmall)
710  {
711  /* extract n small icons */
712  cxsmicon = GetSystemMetrics(SM_CXSMICON);
713  cysmicon = GetSystemMetrics(SM_CYSMICON);
714  ret = ICO_ExtractIconExW(lpwstrFile, phIconSmall, nIndex, nIcons, cxsmicon,
715  cysmicon, NULL, LR_DEFAULTCOLOR);
716  }
717  if (phIconLarge)
718  {
719  /* extract n large icons */
720  cxicon = GetSystemMetrics(SM_CXICON);
721  cyicon = GetSystemMetrics(SM_CYICON);
722  ret = ICO_ExtractIconExW(lpwstrFile, phIconLarge, nIndex, nIcons, cxicon,
723  cyicon, NULL, LR_DEFAULTCOLOR);
724  }
725  return ret;
726 }
727 
728 /***********************************************************************
729  * PrivateExtractIconExA [USER32.@]
730  */
732  LPCSTR lpstrFile,
733  int nIndex,
734  HICON * phIconLarge,
735  HICON * phIconSmall,
736  UINT nIcons )
737 {
738  UINT ret;
739  INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
740  LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
741 #ifdef __REACTOS__
742  if (lpwstrFile == NULL)
743  return 0;
744 #endif
745 
746  TRACE("%s %d %p %p %d\n", lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
747 
748  MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
749  ret = PrivateExtractIconExW(lpwstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
750  HeapFree(GetProcessHeap(), 0, lpwstrFile);
751  return ret;
752 }
BYTE bHeight
Definition: exticon.c:38
#define abs(i)
Definition: fconv.c:206
DWORD get_best_icon_file_offset(const LPBYTE dir, DWORD dwFileSize, int cxDesired, int cyDesired, BOOL bIcon, DWORD fuLoad, POINT *ptHotSpot)
#define max(a, b)
Definition: svc.c:63
#define RT_GROUP_ICON
Definition: pedump.c:375
unsigned short WORD
Definition: ntddk_ex.h:93
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:79
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
WORD offset
Definition: typelib.c:62
UINT WINAPI PrivateExtractIconsW(LPCWSTR lpwstrFile, int nIndex, int sizeX, int sizeY, HICON *phicon, UINT *pIconId, UINT nIcons, UINT flags)
Definition: exticon.c:623
WORD idCount
Definition: exticon.c:51
#define MapViewOfFile
Definition: compat.h:402
BYTE bColorCount
Definition: exticon.c:39
int WINAPI LookupIconIdFromDirectoryEx(_In_reads_bytes_(sizeof(NEWHEADER)) PBYTE, _In_ BOOL, _In_ int, _In_ int, _In_ UINT)
WORD idCount
Definition: ntusrtyp.h:101
ULONG OffsetToDirectory
Definition: ntimage.h:194
__wchar_t WCHAR
Definition: xmlstorage.h:180
WORD idType
Definition: exticon.c:50
#define CP_ACP
Definition: compat.h:99
UINT WINAPI PrivateExtractIconExW(LPCWSTR lpwstrFile, int nIndex, HICON *phIconLarge, HICON *phIconSmall, UINT nIcons)
Definition: exticon.c:677
unsigned char * LPBYTE
Definition: typedefs.h:52
uint8_t entry
Definition: isohybrid.c:63
#define WARN(fmt,...)
Definition: debug.h:111
DWORD dwFileSize
Definition: more.c:36
#define RtlImageRvaToVa
Definition: compat.h:458
struct _ICONIMAGE * LPICONIMAGE
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define SM_CYSMICON
Definition: winuser.h:993
GLuint GLuint end
Definition: gl.h:1545
#define DWORD
Definition: msvc.h:34
int32_t INT
Definition: typedefs.h:56
static BYTE * ICO_LoadIcon(LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
Definition: exticon.c:202
DWORD DWORD
Definition: winlogon.h:75
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD Id
WORD idReserved
Definition: ntusrtyp.h:99
DWORD dwImageOffset
Definition: exticon.c:44
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FALSE
Definition: types.h:117
WINE_DEFAULT_DEBUG_CHANNEL(icon)
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
PIN_DIRECTION dir
Definition: strmbase.h:226
#define SM_CXICON
Definition: winuser.h:952
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:570
smooth NULL
Definition: ftsmooth.c:557
BITMAPINFOHEADER icHeader
Definition: ntusrtyp.h:45
Definition: pedump.c:457
#define FILE_MAP_READ
Definition: compat.h:427
const char * LPCSTR
Definition: xmlstorage.h:183
#define OPEN_EXISTING
Definition: compat.h:426
BYTE bReserved
Definition: exticon.c:40
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
DWORD OffsetToData
Definition: pedump.c:459
#define NE_RSCTYPE_ICON
Definition: exticon.c:72
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
static UINT ICO_ExtractIconExW(LPCWSTR lpszExeFileName, HICON *RetPtr, INT nIconIndex, UINT nIcons, UINT cxDesired, UINT cyDesired, UINT *pIconId, UINT flags)
Definition: exticon.c:261
#define MAX_PATH
Definition: compat.h:26
#define RT_ICON
Definition: pedump.c:365
int WINAPI GetSystemMetrics(_In_ int)
HICON WINAPI CreateIconFromResourceEx(_In_reads_bytes_(dwResSize) PBYTE presbits, _In_ DWORD dwResSize, _In_ BOOL fIcon, _In_ DWORD dwVer, _In_ int cxDesired, _In_ int cyDesired, _In_ UINT Flags)
GLuint GLuint GLsizei count
Definition: gl.h:1545
DWORD biSizeImage
Definition: amvideo.idl:36
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:461
WORD idReserved
Definition: exticon.c:49
GLbitfield flags
Definition: glext.h:7161
type_id
#define SM_CXSMICON
Definition: winuser.h:992
USHORT Id
Definition: ntimage.h:189
int ret
#define SM_CYICON
Definition: winuser.h:953
#define index(s, c)
Definition: various.h:29
#define RtlImageDirectoryEntryToData
Definition: compat.h:460
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define NE_RSCTYPE_GROUP_ICON
Definition: exticon.c:73
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define IMAGE_OS2_SIGNATURE
Definition: pedump.c:90
static const IMAGE_RESOURCE_DIRECTORY * find_entry_default(const IMAGE_RESOURCE_DIRECTORY *dir, const void *root)
Definition: exticon.c:133
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
#define WINAPI
Definition: msvc.h:20
unsigned char BYTE
Definition: ntddk_ex.h:96
WORD length
Definition: typelib.c:63
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
Definition: pedump.c:413
int nIndex
Definition: msvc.h:77
static BYTE * ICO_GetIconDirectory(LPBYTE peimage, LPicoICONDIR *lplpiID, ULONG *uSize)
Definition: exticon.c:215
WORD count
Definition: typelib.c:73
DWORD *typedef HANDLE
Definition: winlogon.h:52
static const IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(const IMAGE_RESOURCE_DIRECTORY *dir, WORD id, const void *root)
Definition: exticon.c:107
HICON hIcon
Definition: msconfig.c:44
GLsizeiptr size
Definition: glext.h:5919
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned short UINT16
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
WORD type_id
Definition: typelib.c:72
#define PAGE_READONLY
Definition: compat.h:127
DWORD dwBytesInRes
Definition: exticon.c:43
#define MultiByteToWideChar
Definition: compat.h:100
#define RtlImageNtHeader
Definition: compat.h:457
#define CreateFileW
Definition: compat.h:400
HANDLE HMODULE
Definition: typedefs.h:75
_Out_opt_ int * cx
Definition: commctrl.h:570
static DWORD USER32_GetResourceTable(LPBYTE peimage, DWORD pesize, LPBYTE *retptr)
Definition: exticon.c:144
CURSORICONDIRENTRY idEntries[1]
Definition: ntusrtyp.h:102
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
GLenum GLuint id
Definition: glext.h:5579
UINT WINAPI PrivateExtractIconsA(LPCSTR lpstrFile, int nIndex, int sizeX, int sizeY, HICON *phicon, UINT *piconid, UINT nIcons, UINT flags)
Definition: exticon.c:647
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
struct icoICONDIR * LPicoICONDIR
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
static BYTE * USER32_LoadResource(LPBYTE peimage, NE_NAMEINFO *pNInfo, WORD sizeShift, ULONG *uSize)
Definition: exticon.c:191
#define LR_DEFAULTCOLOR
Definition: winuser.h:1067
#define UnmapViewOfFile
Definition: compat.h:403
UINT WINAPI PrivateExtractIconExA(LPCSTR lpstrFile, int nIndex, HICON *phIconLarge, HICON *phIconSmall, UINT nIcons)
Definition: exticon.c:731
WCHAR * LPWSTR
Definition: xmlstorage.h:184
icoICONDIRENTRY idEntries[1]
Definition: exticon.c:52
WORD wPlanes
Definition: exticon.c:41
#define LOWORD(l)
Definition: pedump.c:82
struct icoICONDIRENTRY * LPicoICONDIRENTRY
#define HeapFree(x, y, z)
Definition: compat.h:394
WORD wBitCount
Definition: exticon.c:42
GLintptr offset
Definition: glext.h:5920
DWORD Size
Definition: pedump.c:460