I am trying to make a program that stores selected file’s (specifically: executable’s) contents in my program. The problem is I don’t know how…
I have heard that You can do this by writing the contents in a program’s separate resource file.
For example:
You have An executable and You want to store it in Your program in a way that the executable would be there when You close the C++ Program . How Do You do this?
So If anyone know how to do this (mainly the writing executable’s contents in a C++ program), please let me know by answering here .
If you are using Microsoft Visual Studio, then it’s quite easy:
In Add Resource dialog click Import, select “All Files (.)” so that it allows you to import executable file, and then just select the file you want there. When Custom Resource Type dialog pops up, type RCDATA into “Resource type” field.
If you open .rc file, you will see something like this:
and it will generate resource.h with following line:
In code you access it like this:
where pMyExecutable is pointer to first byte of this executable. How to retrieve size of this resource or other useful information you will find here:
http://msdn.microsoft.com/en-us/library/ff468902(v=vs.85).aspx
… here’s an example how you would save binary resource like this on disk:
When you build project with resource like that, this resource will become part of your “program” (.exe, .dll, …).
Hope this helps you 😉