extract icon from .exe

Hello:

I want to extract a .exe's icon and add to my listview.
The problem is:
I can use SHGetFileInfo() to get the system-wide registered icon in the registry,but I can not get the icon of those .exe which are not registerd.

BUt I find exploer can do this.HOw to?
Thanks.
geeboyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NickRepinCommented:
// Load exe or dll
HINSTANCE h=LoadLibraryEx(fileName,0,LOAD_LIBRARY_AS_DATAFILE);

Now you can use, say,

EnumResourceNames(h,RT_ICON,callbackProc,0)

to enumerate all icons.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NickRepinCommented:
You get icon names while enumeration. Use LoadIcon(h,iconName) to load icon itself.
0
geeboyAuthor Commented:
First ,thank you very  much for answering me two questions!
...............
but
Does explorer use this way?

I sole goal is to show some .exe into my listview and add it's icon beside the name.So,as you said,I need loadlibray for every .exe?

And I don't know which icon I need,I only want to show the icon of the .exe which the Explorer show.

So,I only need one icon to show.For example,if I write a .exe and when I view it in the Explorer,there is an icon beside the name of my .exe,how to extract that icon?

Regards.
0
chensuCommented:
Use ExtractIcon or ExtractIconEx.
0
NickRepinCommented:
>>Does explorer use this way ?

Nobody knows this except Microsoft. Most likely, it uses ExtractIcon().

>>I need loadlibray for every .exe?

chensu's suggestion is more easy to implement.

You can use just

HICON hIcon=ExtractIcon(hYourAppInstance,fileName,0);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.