Extract and Save Icon from EXE

milindsm
milindsm used Ask the Experts™
on
Hello,

I need to extract an Icon from EXE and save it to .ico file. I got Icon handle (HICON) using ExtractIconEx API but don't know what to do next.

Cheers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You could use an Icon Extractor. There are multiple free tools (or shareware) available:

http://www.gregorybraun.com/IconEx.html

Author

Commented:
Actually, I need to do it programmatically as I'll use this Icon file to create a shortcut in "Program" Menu
Hi milindsm,

take a look at this previously asked question, I guess you find the answer there: http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_20272806.html

Hope that helps,

ZOPPO
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Commented:
I'd recommend this MSDN article:
http://msdn.microsoft.com/en-us/library/ms997538.aspx
There is a lot of samples. I attached the most attractive that from my opinion should work fine. If I will have time now, I will check it myself.

// Load the DLL/EXE without executing its code
hLib = LoadLibraryEx( szFileName, NULL, LOAD_LIBRARY_AS_DATAFILE );
// Find the group resource which lists its images
hRsrc = FindResource( hLib, MAKEINTRESOURCE( nId ), RT_GROUP_ICON );
// Load and Lock to get a pointer to a GRPICONDIR
hGlobal = LoadResource( hLib, hRsrc );
lpGrpIconDir = LockResource( hGlobal );
// Using an ID from the group, Find, Load and Lock the RT_ICON
hRsrc = FindResource( hLib, MAKEINTRESOURCE( lpGrpIconDir->idEntries[0].nID ),
                      RT_ICON );
hGlobal = LoadResource( hLib, hRsrc );
lpIconImage = LockResource( hGlobal );
// Here, lpIconImage points to an ICONIMAGE structure

Open in new window

Commented:
On CodeProject I found anarticle with the source code that extracts the icons:
http://www.codeproject.com/KB/winsdk/IconExtraction.aspx
I've tested it.
 

Commented:
Both these projects based on IconPro sample.
http://msdn.microsoft.com/en-us/library/aa230367(VS.60).aspx 
 I attached the main file with all functions.

iconpro.c

Author

Commented:
Thanks a lot

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial