Solved

Exe to Resource Q.

Posted on 2001-07-24
7
205 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now