for some reason, I needed to put a file in a DLL. I knew I could put it in a pure resource DLL, but I didn't want anyone else to know how to read the file。 So I want to be able to put this file in a DLL along with the functions on how to read the file. Does anyone know how to do that ? Thanks
CodePudding user response:
Here is one idea. Store the file as base64 encoded with
$ cat file.txt
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
$ cat file.txt | base64 > base64.txt
$ cat base64.txt
SGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29y
bGQKSGVsbG8gV29ybGQKCg==
Then in your c file
static std::string fileout = R"(
SGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29ybGQKSGVsbG8gV29y
bGQKSGVsbG8gV29ybGQKCg==
)";
std::string readme() {
return base64::decode( fileout );
}
You can find several base64::decode() versions here: Base64 decode snippet in C