Hey I found a source code for my needs which accesses a .dll file with an ifstream and reads it with the following code:
std::ifstream File(@"C:\dllfile.dll", std::ios::binary | std::ios::ate);
if (File.fail()) {
printf("Opening the file failed: %X\n", (DWORD)File.rdstate());
File.close();
}
But I decided to read the dll file from the source code itself rather than streaming it from the disk.
To do that I've imported the .dll file into HxD, and exported it as C.
The exported source code of the dll looks like this:
char rawData[2785280] = { 0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, ... };
I've added it as dllcontent.h to my project, included the "dllcontent.h" inside main.cpp. Now I should be able to use the following code to achieve the same as above but with the char array:
std::ifstream File(rawData, std::ios::binary | std::ios::ate);
if (File.fail()) {
printf("Opening the file failed: %X\n", (DWORD)File.rdstate());
File.close();
return -5;
}
But somehow it always triggers the File.fail check means it was not able to open the file?
How could I change the code that I get it working with content of the dll inside my project instead?