Click here to Skip to main content
Click here to Skip to main content

Icon extraction made easy

, 11 Apr 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
Application icons of Win32 executable files can be extracted progamaticallly.

Sample Image - IconExtraction.jpg


Some times you might want to extract the application icon of a Win32 executable file and save it to an icon file. If so, you are at the right place. I have been searching for an article that does this but I couldn't find the one I required. What the article is trying to do is extract the application icon in raw format from a Portable Executable (PE) file and save it to an icon file.

An icon in an executable file is stored in a different format than that in an icon file as you might expect. So it requires a special treatment.

Most of the code in this article is taken from the SDK example named Iconpro. But the Iconpro example lacks a callable interface. This article just did it.

Using the code

You can use the class named CIconExtractor in your projects. For that, just include the header file ExtractResource.h. The class contains one and only method i.e.:

 DWORD ExtractIconFromExe(LPCSTR SourceEXE,
                          LPCSTR TargetICON,UINT IconIndex);

The parameter SourceEXE is the name of the executable file whose icon is to be extracted, the TargetICON is the name of the new icon file. The parameter IconIndex needs a bit of explanation. An executable file can contain more than one icon. The icon that appears first in the resource directory of the executable file will be taken as the application icon by the Explorer. To extract the application icon, give IconIndex a value 0. If you use a value greater than 0, make sure that the value is less than the constant MAX_ICONS. You can change the value of the constant MAX_ICONS to a desired one.

Usually, an executable file will have resources other than icons, such as bitmaps, strings, cursers etc. This code is looking only for icons.

That's all, enjoy it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
Shooting for the Moon.

Comments and Discussions

QuestionHow use this code in Console App? [modified] Pinmembertux-dev11-May-13 2:06 
QuestionSize of icon? Pinmemberkiranin26-May-09 21:01 
GeneralReplace icon of EXE file Pinmemberbabyleung12321-Feb-06 6:45 
GeneralRe: Replace icon of EXE file PinmemberMohd Nisamudheen S.20-Mar-06 19:49 
GeneralRe: Replace icon of EXE file PinmemberOm Rudi1-Jun-07 8:03 
GeneralMe, again! :-P PinmemberDarth_Sulfur3-Nov-05 11:27 
GeneralRe: Me, again! :-P PinmemberMohd Nisamudheen S.11-Nov-05 23:04 
GeneralHaving a little trouble... :-S PinmemberDarth_Sulfur13-Oct-05 13:44 
GeneralRe: Having a little trouble... :-S PinmemberMohd Nisamudheen S.13-Oct-05 23:26 
GeneralRe: Having a little trouble... :-S PinmemberDarth_Sulfur14-Oct-05 6:05 
GeneralRe: Having a little trouble... :-S PinmemberMohd Nisamudheen S.14-Oct-05 19:44 
General:) PinsussIBone©12-Apr-05 5:28 
GeneralRe: :) PinmemberMohd Nisamudheen S.12-Apr-05 19:01 
QuestionDLLs ? PinmemberPazu12-Apr-05 2:19 
AnswerRe: DLLs ? PinmemberMohd Nisamudheen S.12-Apr-05 19:05 
GeneralRe: DLLs ? PinmemberPazu13-Apr-05 7:42 
GeneralRe: DLLs ? PinmemberMohd Nisamudheen S.15-Apr-05 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.1 | Last Updated 12 Apr 2005
Article Copyright 2005 by Nisamudheen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid