0

I'm struggling to find any helpful resources on how I can use the resource section within a executable to store and retrieve data.

If anybody would be kind enough to explain it and possibly provide some sample code, I would be most grateful.

Edit - Working with Windows Visual c++ 2008.

Ryan
  • 957
  • 5
  • 16
  • 34
  • What OS are you working with? What have you tried so far? – Olaf Dietsche Oct 24 '12 at 19:42
  • 2
    The executable format depends on your OS, not your programming language. Is this a Windows PE format file? A Linux ELF file? – Ben Voigt Oct 24 '12 at 19:42
  • 2
    Have you considered using a separate data file instead? Is there a particular reason to need to store data in the executable? – John Oct 24 '12 at 20:26

1 Answers1

1

There is a portable way to encode files in an executable: you encode your files in specific structure. Ex:

// header MyFile.h
static const int fileSizeInBytes = 42;
extern const unsigned char myFileContents[fileSizeInBytes];

// source MyFile.cpp
const unsigned char myFileContents[fileSizeInBytes] =
{
    0x0A, 0x35, 0x25, //...
    // ...
    0xAB, 0xCD, 0xEF
};

You can find some tools for automatically generating those files (for example, with Qt, there is rcc).

Also, there is a more specific answer here (Windows, PE format). You can also look here (although it's for the Irrlicht Engine, the code is rather clear and small, easily understandable) (still for PE format). I don't know for the ELF format.

Community
  • 1
  • 1
Synxis
  • 9,236
  • 2
  • 42
  • 64