Solved

Exe to Resource Q.

Posted on 2001-07-24
7
209 Views
Last Modified: 2010-04-06
Hi all
I was wondering if it's possible to take a small standalone executable and compile it into a RES file and use it as a resource in my application...ie, the exe embedded into my main exe. How would the res file be accessed by my main app? How would I call the procedure etc.... Anbody have any code examples. TIA
T.
0
Comment
Question by:tongalite
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6315610
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6316097
hi,
here is example to put an exe inside an exe:

with notepad make a .rc file that looks like this:

 TESTFILE  EXEFILE  C:\TEST.EXE

and save as myres.rc

compile myres.rc with brcc32 to get myres.res then make sure myres.res is in same dir as project.

then in unit do:

{$R *.DFM}
{$R MYRES.RES}

procedure ExtractRes(ResType, ResName, ResNewName : String);
     var
       Res : TResourceStream;
     begin
       Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
       Res.SavetoFile(ResNewName);
       Res.Free;
     end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ExtractRes('EXEFILE','TESTFILE','C:\TEST_EXE_FROM_RES.EXE');
ShellExecute(Form1.Handle,'open','c:\Test_exe_from_res.exe',nil,nil,SW_SHOWNORMAL);
end;


that wil lextract the exe to a file called C:\TEST_EXE_FROM_RES.EXE and execute it.

afterwards you can call DeleteFile('C:\TEST_EXE_FROM_RES.EXE') to delte it if you want to.

Regards Barry
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6318987
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:Gwena
ID: 6319133
Grr...EE acting up today

Hi tongalite :-)

  Are you wanting to place a small exe inside a res file in your program and run it from there?  If so you will probably not have much luck...although I have seen this done with a dll.

  It's easy though to store a small exe in a res file and then extract it to disk and run it from disk..as inthe has shown you.. or you could tack it onto the end of your exe and extract it from there...in any case I recommend compressing it before you add it just to keep the size down :-)

  It's also possible to add code to your exe so that it can modify itself as it runs by adding any other exe to it's end and renaming itself to the name of that exe... then when that program is run your code executes first...then the exe that was tacked on executes....it's pretty cool and if you compress the second exe you can usually keep total size the same as it was :-)
0
 
LVL 3

Author Comment

by:tongalite
ID: 6329990
Hi
inthe & Gwena,
Thanks for the response,

<snip, from Gwena>
>Are you wanting to place a small exe inside a res file in >your program and run it from there?  If
>so you will probably not have much luck...although I have >seen this done with a dll.

Yeah, that's what I had in mind. I have only just accessed your comments so I'll give your proposal a whirl (inthe)
Cheers
T.
<I just love this great messageboard and all you cool dudes who provide the help..superb!>
0
 
LVL 3

Author Comment

by:tongalite
ID: 6330539
Hi inthe,
Wow! worked like a dream! thanks.
I will have much fun with your example code
cheers
T.
Thanks also to Gwena:)
Have fun!
0
 
LVL 17

Expert Comment

by:inthe
ID: 6331522
no problem
 
cheers ;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question