If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.

Re: Embed .exe in a c++ project

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?

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.

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?

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.

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.