Solved

Exe to Resource Q.

Posted on 2001-07-24
7
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 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