Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 388
mrg95 Avatar asked May 29 '13 19:05

mrg95


2 Answers

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.

like image 192
Gearoid Murphy Avatar answered Nov 09 '22 03:11

Gearoid Murphy


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.

like image 1
V-X Avatar answered Nov 09 '22 04:11

V-X