mrg95
mrg95

Reputation: 2418

C++ Embed external .exe into my compiled .exe

I have a quick question on a topic that I'm quite a noob about. I have a program I made that sends a command to another .exe in a folder I called "tools". I send it in this format:

system("tools\\program.exe -r -w file.dat file_new.dat");

Everything works great, however, when I build my program into a .exe it will require the other executable to be in a second folder, obviously. Is there any way to include the external .exe into my project so the final product is just one .exe?

I am using Visual Studio 2008 (lol) and run windows 7 64bit.

Thanks :)

Upvotes: 5

Views: 6908

Answers (2)

V-X
V-X

Reputation: 3029

You can add the file to resources. And before the command is executed, you can check, if the second executable exists. If it doesn't exist, you have to extract the data from resource and store to the file...

This thread was dealing with reading html from resource. It is very similar with binary file.

Upvotes: 1

Gearoid Murphy
Gearoid Murphy

Reputation: 12116

Typically, the management of external dependencies would be handled by the installer. NSIS is my favoured solution for the Windows platform.

The alternative: Convert the binary to a base64 encoding and embed it as a header file in your project. When the application is run, convert the base64 representation of the exe to a binary sequence and then output that sequence of bytes to a file in a temporary directory (like C:\windows\temp or %AppData%\Local\Temp). Then run the exe. Once you're done with it, remove the exe.

Upvotes: 5

Related Questions