I am having a sample.dll, a sample.txt file and sample.exe. sample.exe uses sample.dll functions. I am opening sample.txt and reading its contents in sample.dll. Everytime I run sample.exe I need to place sample.txt at .exe location. I don't want to do like that. Now what I want is to embed sample.txt in sample.dll, without need to place sample.txt file while running .exe.
Asked
Active
Viewed 303 times
1
-
2How is this related to Linux? Please don't spam tag. Also please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Jan 31 '19 at 12:47
-
2@Manoj, Is it C or C++? Please mark only one tag. Some people are not too thrilled when the two languages are mixed. 2ndly, if you can "embed" the text file or not, depends on what you are doing with the text file and what it contains. It would be possible to answer these questions, if you could add a short version of that text file here and of the source code of that `dll` and the `exe` file. It is difficult to tell otherwise. – Duck Dodgers Jan 31 '19 at 12:50
-
Possible duplicate of [Embed Text File in a Resource in a native Windows Application](https://stackoverflow.com/questions/2933295/embed-text-file-in-a-resource-in-a-native-windows-application). But the resource would be stored in the DLL rather than the EXE. – Ian Abbott Jan 31 '19 at 12:56
-
There are two questions here:How to "embed" a string in your DLL and how to access it like a file. First question can be as simple as `const char *text = ".....".` There are more windows-specific ways, see "resources". The second question has no uniform answer in C, but in C++ you can use streams to read your text, and then create `istringstream` rather than `ifstream`. – Jan 31 '19 at 13:31