text file as custom resource
-
Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?
-
Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?
It depends on which path you choose. If you want to be able to use it exactly as a file (i.e. open with
CreateFile
orstd::ifstream
) it would be a lot of work; don't even go down that road. The easiest way would be to write your own stream class that reads from resources; for this task I'd use the Boost.Iostreams[^] library.Steve
-
Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?
whenwood wrote:
I want to include the file as resource in the .exe, so that no one can read the file.
I believe much like dialogs, menus, toolbars and string resources file resources could easily be read using Visual Studio. Just open the binary with Visual Studio as a resource. If your intent is to ultimately store this information privately then encrypt it in a file. Trying to write info back to a file within the binary is error prone.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
-
Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?
You can use, sure, import resource command in resource editor and choose the file as external file; the resulting binary will now contain a resource that can be accessed using FindResource, LoadResource, LockResource etc. (Perhaps is even better to use a separate dll only for this purpose). On the other hand, ifstream (basic_ifstream) have contructor only with a filename. Maybe basic_istream will do it, passing in constructor a basic_streambuf for resource and probably false for 2nd argument, _Isstd. I think implementing a derived class from basic_streambuf to use with the text resource file can do it.