Solved

Exe to Resource Q.

Posted on 2001-07-24
7
207 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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