Embed Data in a C++ Program

Embed data in a C++ program

You can use objcopy to bind the contents of the file to a symbol your program can use. See, for instance, here for more information.

How to permanently store information using C program?

People have done this all kinds of ways. In order from best to worst (in my opinion):

  1. Use a registry or equivalent. That's what it's there for.
  2. Use an environment variable. IMO this is error prone and may not really be what you want.
  3. Store a file on your user's computer. Easy to do and simple.
  4. Store a file on a server and read/write to the server via the network. Annoying that you have to use the network, but OK.
  5. Modify your own binary on disk. This is fun as a learning experience, but generally inadvisable in production code. Still it can be done sometimes especially using an installer.
  6. Spawn a background process that "never" dies. This is strictly worse than using a file.

When embedding CLIPS into C Language, what function can used to modify the fact from C program

Section 4.4 of the Advanced Programming Guide, http://clipsrules.sourceforge.net/OnlineDocs.html, has a list of functions that can be used on facts. The fact-set queries and distributed actions in section 12.9.12 of the Basic Programming Guide are also useful for retrieving and manipulating facts from a C program. For example, you could use the following function call to retrieve all person deftemplate facts where the value in the age slot was greater than 18:

   DATA_OBJECT result;

Eval("(find-all-facts ((?p person)) (> ?p:age 18))",&result);

How to embed a file into an executable?

A portable way is to define a function like

typedef unsigned char Byte;

Byte const* pngFileData()
{
static Byte const data =
{
// Byte data generated by a helper program.
};
return data;
}

Then all you have to do is to write a little helper program that reads the PNG file as binary and generates the C++ curly braces initializer text. Edit: @awoodland has pointed out in comment to the question, that ImageMagick has such a little helper program…

Of course, for a Windows-specific program, instead use the ordinary Windows resource scheme.

Cheers & hth.,



Related Topics



Leave a reply



Submit