-
May 24th, 2009, 07:59 AM
#1
Embed .exe in a c++ project
Hey,
Is it possible to embed an extenal executable in a project?
For example, if i want to run wget.exe, i would normally included the wget executable in the same directory as the main program, and call system("wget.exe http://domain.com/file.txt");.
But I want my program to be minimal and only have 1 file. Instead of keeping two executable, I would like to keep everything in one file, for simplicity and less chance of messing up the program.
How would i do this?
Thanks.
-
May 24th, 2009, 08:33 AM
#2
Re: Embed .exe in a c++ project
-
May 24th, 2009, 10:05 AM
#3
Re: Embed .exe in a c++ project
Thanks Alex!
I downloaded the demo and tried to build it but i didn't. I needed afxwin.h, which is MFC, which i dont have. Im using vc++ express and can't afford the professional.
Is there a way without having to use the MFC class?
-
May 24th, 2009, 10:14 AM
#4
Re: Embed .exe in a c++ project
It looks like demo project is built with MFC, and BinRes class doesn't have MFC dependencies. You can use this class in non-MFC project by the same way as it is done in the demo project.
-
May 24th, 2009, 02:23 PM
#5
Re: Embed .exe in a c++ project
But I want my program to be minimal and only have 1 file. Instead of keeping two executable, I would like to keep everything in one file, for simplicity and less chance of messing up the program.
Yeah, this is what installers are about...
Best regards,
Igor
-
May 25th, 2009, 08:58 AM
#6
Re: Embed .exe in a c++ project
Originally Posted by Alex F
It looks like demo project is built with MFC, and BinRes class doesn't have MFC dependencies. You can use this class in non-MFC project by the same way as it is done in the demo project.
Sorry, but I'm a noob.
I downloaded the non-demo file, and realized
Code:
#include "testHarness.h"
was in the binres.cpp source file. testHarness was the demo project. The header file was not included with the non-demo file, and when i comment it out, it wouldn't compile. There were errors about undeclared identifiers.
Could you help me create a project that simply does what binres supposed to do without anything else?
Originally Posted by Igor Vartanov
Yeah, this is what installers are about...
I considered that, but I'd prefer a more portable application, without the need of installation.
On another side, I found this http://www.codeguru.com/forum/showthread.php?t=373518
It's a cool concept, and i tried it out (BTW, im running ubuntu linux with a windows xp virtual machine).
But it didn't work. I used the fstream to output the array onto a file. but when i compared the hex with the original file, it wasn't the same. Oh well. I'll try to solve that problem later.
But if it does work, would there be a way to execute the array without having to actually make a file on the hard drive, but rather execute it directly from memory?
-
May 25th, 2009, 10:13 AM
#7
Re: Embed .exe in a c++ project
What you are wanting to do is what DLLs were designed to do. wget is open source so you could probably make it a dll without too much work (there might even be a dll version of the project somewhere, I haven't checked). Other than that, Microsoft has already done a good deal of the hard work for you with the CInternetConnection class. Consider using that (or the WinInet API directly) to get your file from the web instead of relying on external programs.
http://msdn.microsoft.com/en-us/library/s7seyaek.aspx
http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx
-
May 26th, 2009, 03:53 AM
#8
Re: Embed .exe in a c++ project
Originally Posted by benchaz
No it's not that cool. The cool one (at least in the Windows world) is to keep the binary in resources and dump it to disk whenever it's needed.
But it didn't work. I used the fstream to output the array onto a file. but when i compared the hex with the original file, it wasn't the same. Oh well. I'll try to solve that problem later.
But if it does work, would there be a way to execute the array without having to actually make a file on the hard drive, but rather execute it directly from memory?
Nope, executable file is supposed to be loaded by system loader, and the latter works only with files on file system but not in-memory ones. Otherwise you are to do all the work that loader does. I doubt you ever want to.
Well, it seems that in your case the best approach would be to just forget about wget and try to find the library with the same functionality. Or otherwise do it usual way, like others do, with installers, resources, whatever.
Best regards,
Igor
-
August 29th, 2010, 09:38 AM
#9
Re: Embed .exe in a c++ project
Originally Posted by Igor Vartanov
Yeah, this is what installers are about...
One of the coolest tools I use are Process Explorer and Process Monitor
http://technet.microsoft.com/en-us/s.../bb896653.aspx
http://technet.microsoft.com/en-us/s.../bb896645.aspx
They are cool not only for what they do, but also because they don't need installation. Every program looks like a single, standalone exe. Of course, they use the embedded resource technique for every extra file they need.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|