Sometimes it is necessary to embed resource such as icons, images, texts or even arbitrary binary data into executables. There several approaches for acomplishing this:
Windows:
*) Create a resource script, for instance resource.rc, and compile the resource to object code with the MSVC resource compiler. rc.exe or GCC/Mingw resource compiler, windres.exe. Then build the executable by linking the application object code with the compiled resource.
*) Functions: FindResource, LoadResource, SizeofResource, LockResource
*) Icon: On Windows it is the only way to add an icon to an executable.
Unix-like:
*) objcopy tool.
*) ld (GNU ld linker)
*) Icon: Native executables for MacOSX, Linux and BSD don't support embedded icon as Windows.
Portable:
*) Base 64 encoding - Initialize some string global variable with the resource encoded as base64 string. When the resource is needed, the program decode the global variable from base64 to a byte stream, byte array, string or file.
*) Byte array encoding - The resource is turned into a C++ source code containing the resource encoded as a byte-array. The source is then compiled to object code and added to the application at linking time. This technique is better implemented with an custom external code generator or off-the-shelf tool such as:
**) image-magick -> Can convert images into a header files containing the image bytes.
$ convert image.png image1.h
**) xdd - utility
$ xxd file.png -i
$ xxd file.png -i > resourcedata.hpp
Partager