winexec
asked on
Icon extraction from EXE
I need to extract the icons from an executable, into a one .ico file. The problem is the icons can have different color depths and sizes, so I cannot simply use a function like ExtractIcon().
I think I have to enumerate the resources, find RT_GROUP_ICON and RT_ICON types, extract the data and combine the bits into a .ico file.
I need that to work on XP/Vista.
Thank you.
I think I have to enumerate the resources, find RT_GROUP_ICON and RT_ICON types, extract the data and combine the bits into a .ico file.
I need that to work on XP/Vista.
Thank you.
you might find the following helpful:
http://www.ciuly.com/delphi/win32api/resources/enumNameLang/index.html
http://www.ciuly.com/delphi/misc/madshi/extractIcon/index.html
http://www.ciuly.com/delphi/win32api/resources/enumNameLang/index.html
http://www.ciuly.com/delphi/misc/madshi/extractIcon/index.html
ASKER
I'm interested to see a Delphi solution.
ASKER
@ciuly:
Thanks, but I think Madshi's components aren't free.
Thanks, but I think Madshi's components aren't free.
Hi
Try the following
var
FIcon : TIcon;
FApp : String;
begin
FApp := 'Application.EXE';
FIcon := TIcon.Create;
FIcon.Handle := ExtractIcon(Handle, PChar(FApp), 0);
ImageList1.AddIcon(FIcon);
end;
Try the following
var
FIcon : TIcon;
FApp : String;
begin
FApp := 'Application.EXE';
FIcon := TIcon.Create;
FIcon.Handle := ExtractIcon(Handle, PChar(FApp), 0);
ImageList1.AddIcon(FIcon);
end;
they are free for non-commercial use.
in your case, all you need is madbasic which is toitally free: http://help.madshi.net/madBasic.htm
a good alternativ: http://www.wilsonc.demon.co.uk/d10resourceeditor.htm
in your case, all you need is madbasic which is toitally free: http://help.madshi.net/madBasic.htm
a good alternativ: http://www.wilsonc.demon.co.uk/d10resourceeditor.htm
ASKER
atul_parmar, really, did you read my question? "The problem is the icons can have different color depths and sizes, so I cannot simply use a function like ExtractIcon()."
Sorry I really didn't read it first. You can use ExtractIconEx; it takes care of size and color depths.
https://www.experts-exchange.com/questions/20956969/Getting-48X48-Icons.html
and this too
http://wall.riscom.net/books/delphi/del_faqs/1339.html
https://www.experts-exchange.com/questions/20956969/Getting-48X48-Icons.html
and this too
http://wall.riscom.net/books/delphi/del_faqs/1339.html
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi winexec,
If you use the units in my previous post, you can use the following sample procedure to save a particular icon from a multi-cion image.
As you're Advanced on this subjec, I believe you don't need more explanation.
procedure TIconViewer.SaveSelectedIm ageIconCli ck(Sender: TObject);
Var
Stream : TMemoryStream;
ImgNr: integer;
Header : TIconHeader;
ResInfo : TFileIconResInfo;
StartPos,StreamPos : DWord;
begin
With ICOListBox DO begin
IF (ItemIndex<0)
OR (ItemIndex>Icon.Images.Cou nt)
OR (Icon.Images.Count<= 0{ 1}) Then exit;
ImgNr:= IcoListbox.ItemIndex;
With Header do begin
wReserved:=0;
wType :=1;
wCount :=1; // only the selected icon
end;
Stream:=TMemoryStream.Crea te;
try
With Stream do begin
StartPos:= Position;
Write(Header,SizeOf(Header ));
ResInfo.ResInfo:= Icon.Images.Image[ItemInde x].Info;
ResInfo.dwImageOffset:= ImgNr; // selected Ico
Write(ResInfo,SizeOf(ResIn fo));
StreamPos:= Position-StartPos;
Position:=SizeOf(Header)+( SizeOf(Res Info))- SizeOf(DWord);
Write(StreamPos,SizeOf(Str eamPos));
Position:=StreamPos;
Icon.Images.Image[ItemInde x].WriteIc onDataToSt ream(Strea m);
if Stream.Size > 0 then Stream.SaveToFile('New.ico ');
end
finally
Stream.Free;
end;
end;
end;
Hope this can be helpful for others too.
If you use the units in my previous post, you can use the following sample procedure to save a particular icon from a multi-cion image.
As you're Advanced on this subjec, I believe you don't need more explanation.
procedure TIconViewer.SaveSelectedIm
Var
Stream : TMemoryStream;
ImgNr: integer;
Header : TIconHeader;
ResInfo : TFileIconResInfo;
StartPos,StreamPos : DWord;
begin
With ICOListBox DO begin
IF (ItemIndex<0)
OR (ItemIndex>Icon.Images.Cou
OR (Icon.Images.Count<= 0{ 1}) Then exit;
ImgNr:= IcoListbox.ItemIndex;
With Header do begin
wReserved:=0;
wType :=1;
wCount :=1; // only the selected icon
end;
Stream:=TMemoryStream.Crea
try
With Stream do begin
StartPos:= Position;
Write(Header,SizeOf(Header
ResInfo.ResInfo:= Icon.Images.Image[ItemInde
ResInfo.dwImageOffset:= ImgNr; // selected Ico
Write(ResInfo,SizeOf(ResIn
StreamPos:= Position-StartPos;
Position:=SizeOf(Header)+(
Write(StreamPos,SizeOf(Str
Position:=StreamPos;
Icon.Images.Image[ItemInde
if Stream.Size > 0 then Stream.SaveToFile('New.ico
end
finally
Stream.Free;
end;
end;
end;
Hope this can be helpful for others too.
ASKER
@ciuly:
I've installed Madsi's components and tried your sample. I don't know the reason, but SaveIconGroupResourceW fails to save the .ico file ('saved_main.ico' in your sample). The result is true, but the file isn't saved. I've also tried with a full path for the ico file, it didn't save it. I didn't find the time to debug it more.
@bernani:
I've downloaded your demo, it works fine. Thanks.
I've installed Madsi's components and tried your sample. I don't know the reason, but SaveIconGroupResourceW fails to save the .ico file ('saved_main.ico' in your sample). The result is true, but the file isn't saved. I've also tried with a full path for the ico file, it didn't save it. I didn't find the time to debug it more.
@bernani:
I've downloaded your demo, it works fine. Thanks.
I just retested the demo using the steps outlined on the page and it works just fine. dunno what to say. it could be the language, though if you don't change anything in the project (no files, no nothing, just compile) it should maintain the romanian language as it is currently hardocded in the demo.
I cannot fix something I cannot reproduce so I'll just assume something was different in your test then in mine.
I cannot fix something I cannot reproduce so I'll just assume something was different in your test then in mine.
ASKER
ciuly:
You're right. I've re-tested your app and it works fine (I've tested it even with icons with different color depths and sizes). I'm not sure why it didn't work initially, when I've changed the MainIcon, it was my fault.
But I will use the solution proposed by Bernani, I don't like to use other components (even if they are free).
You're right. I've re-tested your app and it works fine (I've tested it even with icons with different color depths and sizes). I'm not sure why it didn't work initially, when I've changed the MainIcon, it was my fault.
But I will use the solution proposed by Bernani, I don't like to use other components (even if they are free).
Have you tryed using ressource hacker?