madRes - saving .ico file

delphi package - madRes, madTools, madStrings, ...
Post Reply
Nikse
Posts: 3
Joined: Sat Nov 13, 2004 9:03 pm
Location: Denmark

madRes - saving .ico file

Post by Nikse »

Hi !

madRes looks very nice indeed.

I've written a small icon grabber using ExtractIcon(Ex) to list all icons in
an .exe file... but delphi's built in TIcon cannot save icons in WinXP
alphablended format (or even in 256 colors).
Is this (listing all icons + saving) possible using madRes... and how (sample code)?

TIA
Nikse
madshi
Site Admin
Posts: 10365
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Enumerating resources currently isn't exported by madRes. It would be possible to do that, but would need some work.

You can use this approach, though:

(1) Use LoadLibraryEx(LOAD_LIBRARY_AS_DATAFILE) to load the target exe/dll into memory.
(2) Use EnumResourceNames(dllHandle, RT_GROUP_ICON) to enumerate all icon groups.
(3) Use FreeLibrary to unload the target exe/dll again.
(4) Use madRes.BeginUpdateResourceW to open the exe/dll for madRes.
(5) Use madRes.SaveIconGroupResourceW to save all icon groups (which you enumerated in step (2)) to a file.
(6) Call madRes.EndUpdateResourceW and discard any changes.

Sorry, no time to write sources for you.
Nikse
Posts: 3
Joined: Sat Nov 13, 2004 9:03 pm
Location: Denmark

Post by Nikse »

Thx, great!

Almost there... I think. Enumeration is working (according to ResHacker).

I can save the main icon like this:
result := SaveIconGroupResourceW(resUpdateHandle, 'MAINICON', 0, 'c:\test.ico');

But how do I save an icon called "74" from RT_ICONS?
result := SaveIconGroupResourceW(resUpdateHandle, 'RT_ICON_74', 0, 'c:\test2.ico'); // does not work
madshi
Site Admin
Posts: 10365
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

SaveIconGroupResourceW is only meant for icon groups, not for single icons. If you need to extract single icons, you probably need to look at how madRes does it for icon groups and then modify/extend the functionality for single icons. But why do you need that? Usually all single icons are part of at least one icon group.
Post Reply