954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Embed text files into C++ Win32 Application

I have a Win32 Application in C++. At runtime, It loads a Matrix stored as TXT file in the working directory with I/O functions.

I have problems to distribute my program (EXE and DLL) because people normally forget to move the text files together with the Application.

How can I embed this TXT file into the application and distribute only one file (EXE or DLL)

Thanks.

harvybcn
Newbie Poster
2 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

I don't know of a way to embed the .txt file itself inside the executable like a resource, but you could set up a struct or table of strings or something inside the program instead of a text file.

Alternatively, if you have an IDE like MS Visual Studio, you could create a setup project which includes the text file, the executable, and any other files you want and have it all installed in the appropriate directory.

Hope this helps.

Jeff

jeff.reith
Newbie Poster
7 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

If your exe and dll can remain together, why not txt file. Maybe you can distribute them together as a zip file.
Or you can use a free installer for distributing "everything" as a single "exe"
Like http://www.createinstall.com/index.html
Vinayak

vinayakgarg
Junior Poster in Training
83 posts since Jan 2010
Reputation Points: 19
Solved Threads: 17
 

It's easy:
- keep your .txt file in the /res folder
- in your project .rc file add the following:
IDS_WHATEVER_TXT RCDATA DISCARDABLE "res\\Myfile.TXT" (mind the double quotes)
- in the resource.h file:
#define IDS_WHATEVER_TXT whateverPleasesYou
the above will embed the .txt file in your executable.
at run time extract and interpret the contents.

alex

alexb119
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: