How Can I Embed a text file in Code ?
-
Hello Friends I am having one text file storing some constant color data. But I dont want to read it from Disk everytime when I am showing up all these color into Dialog. I need a way that file get embed into project and when I open my color Dialog,it get read tht file and show up all colors. Any Ideas? Regard Yogesh
With a text file, just embed the content as a text variable to your source file:
static const char * lpszColorData = "<color data as text>";
and use the variable like the buffer used so far when reading from the file.
-
Hello Friends I am having one text file storing some constant color data. But I dont want to read it from Disk everytime when I am showing up all these color into Dialog. I need a way that file get embed into project and when I open my color Dialog,it get read tht file and show up all colors. Any Ideas? Regard Yogesh
You can also use resources to embed text file into your project. Say the name the text file is data.txt, then in the .rc file add
IDS_TEXT_DATA RCDATA DISCARDABLE "Data.TXT"
and in the resource.h give assign appropriate constant to it
#define IDS_TEXT_DATA 5555
-
You can also use resources to embed text file into your project. Say the name the text file is data.txt, then in the .rc file add
IDS_TEXT_DATA RCDATA DISCARDABLE "Data.TXT"
and in the resource.h give assign appropriate constant to it
#define IDS_TEXT_DATA 5555
That's it! The only answer that actually answers the question as posed. While the other answers achieve (roughly) the same functionality, this is the only answer I'd be satisfied with if it were my question. Nice work. :thumbsup: What if the text file is 2000 lines long and created by some other program? The other answers will all require more work. Admittedly the values will be stored as text, rather than binary - a size penalty, though otherwise this would be my preferred approach. There are pros and cons to each method. Whom are we to assume that we understand the relevance of each of these to the project in question? Let alone give a response that doesn't answer the posed question...
-
That's it! The only answer that actually answers the question as posed. While the other answers achieve (roughly) the same functionality, this is the only answer I'd be satisfied with if it were my question. Nice work. :thumbsup: What if the text file is 2000 lines long and created by some other program? The other answers will all require more work. Admittedly the values will be stored as text, rather than binary - a size penalty, though otherwise this would be my preferred approach. There are pros and cons to each method. Whom are we to assume that we understand the relevance of each of these to the project in question? Let alone give a response that doesn't answer the posed question...
The only fear I have is of security. If the developer intends to store security critical information in this text file, then I think he is inviting trouble from the hackers/crackers or what ever, as the resource file is wide open for extraction and manipulation. Like pointed rightly by you, it's up to the OP to chose the method :thumbsup:
-
The only fear I have is of security. If the developer intends to store security critical information in this text file, then I think he is inviting trouble from the hackers/crackers or what ever, as the resource file is wide open for extraction and manipulation. Like pointed rightly by you, it's up to the OP to chose the method :thumbsup:
It really doesn't make much difference. In fact, with encryption this method could be more secure (difficult and time consuming to reverse - though one can still find/rip and use the decryption function as supplied in the exe along with the encrypted text). There might be a difference of 5-10 mins in understanding the binary data as opposed to the (plain) text version using OllyDbg or (preferably) IDA Pro Advanced. However, I don't see security as a consideration (nor was it mentioned) when storing colour values. :shrugs:
-
It really doesn't make much difference. In fact, with encryption this method could be more secure (difficult and time consuming to reverse - though one can still find/rip and use the decryption function as supplied in the exe along with the encrypted text). There might be a difference of 5-10 mins in understanding the binary data as opposed to the (plain) text version using OllyDbg or (preferably) IDA Pro Advanced. However, I don't see security as a consideration (nor was it mentioned) when storing colour values. :shrugs:
Hello Friends Thanks EveryOne For their thoughtful consideration for my question. But still I didnt Get my Answer. Till Now, i am reading the file from disk and stroing it into Color Arrays. Directly,i cant assign my RB Values to ColorArray as my File is Having more than 2000 lines and it can be changed later on As it is produced from Third party. And Now,I dont want to keep this file on Disk for Security purpose even. AS i Think,Would it be preferrable If i save color text file into Header file and add it into project and is ther any some way to get data into Structures by using CStdioFile or Some other way ? Any Other Ideas ?? Thanks & Regards Yogesh
-
You can also use resources to embed text file into your project. Say the name the text file is data.txt, then in the .rc file add
IDS_TEXT_DATA RCDATA DISCARDABLE "Data.TXT"
and in the resource.h give assign appropriate constant to it
#define IDS_TEXT_DATA 5555
-
Hello Friends Thanks EveryOne For their thoughtful consideration for my question. But still I didnt Get my Answer. Till Now, i am reading the file from disk and stroing it into Color Arrays. Directly,i cant assign my RB Values to ColorArray as my File is Having more than 2000 lines and it can be changed later on As it is produced from Third party. And Now,I dont want to keep this file on Disk for Security purpose even. AS i Think,Would it be preferrable If i save color text file into Header file and add it into project and is ther any some way to get data into Structures by using CStdioFile or Some other way ? Any Other Ideas ?? Thanks & Regards Yogesh
Then Lakamraju's answer for you was perfect - The 2rd party just makes a file, which you refer to from your rc resource, and it gets built it. This is less easy that the previous answers to work with, but it satisfies the requirements you've just written (and should have written in the original question - none of us are psychic. Well, maybe Carlo...) Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
-
Hello If i Use it like to embed in resource then My Question is that then Do we need text file on Disk when I use exe at other place ? Regards yogesh
Resources are built into the executable. You don't need an icon file for your executable to have an icon at another place either. Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
-
Resources are built into the executable. You don't need an icon file for your executable to have an icon at another place either. Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!