embed resource into source code

I’m tidying a project which contains multi drivers, boot resources. drivers are packed in zip, and included in resource file. boot resource are included directly in resource file.

The shortages:

  1. need to add a source id whenever we need to add a resource
  2. we need extra steps to use resource: a. locate the resource; b. decompress; c. attach the data to final data structure
  3. resources can be viewed and modified through many tools, we can not assume a resource is available when a program starts

The advantages are due to they are embedded:

  1. no win64 file system redirection issue, resources are in memory when a program is running.
  2. easier to use, no need to copy resources when we copy programs

Thanks to C++ 11, we can revamp this to overcome the shortages:

Compiling resource as arrays.

struct SvcInfo
const wchar_t* name;
int type;
DWORD start;
const wchar_t* path;
const wchar_t* group;
int flag;
std::vector<unsigned char> _32bit;
std::vector<unsigned char> _64bit;

SvcInfo g_svc[]=
[](){static unsigned char a[] = {
#include “fastreboot_x86.h”
return std::vector<unsigned char>(a,a + sizeof(a));}(),
[](){static unsigned char a[] = {
#include “fastreboot_x64.h”
};return std::vector<unsigned char>(a,a + sizeof(a));}()

Each drivers are compiled into an array, and included into source code directly.

By using lambda expression of C++ 11, we embed the header file as part of constructor.

These are the extra benefits:

  1. resources are compiled into static data, part of the final code(actually in data section), we can assume they are available and unchanged
  2. resources are compiled into final data structure directly.

We use CMake to manage the build procedure.


  1. build drivers, boot program
  2. use cmake -e to pack them into zip file
  3. build exe,dll to include the generated zip file


  1. build drivers, boot program
  2. use cmake custom target/command generate header files
  3.  build exe, dll to include the generated header files



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s