I'm wrapping files with Visual C++ 2008, I've figured out how to embed them but I can't figure out how to retrieve them. I have some C++ experience, but none with Win32 or Visual C++. The goal of the wrapping is to run some code, and then if everything okay it can run the embedded file.
I'm wrapping many different files, so code reuse is key, and in all cases I won't know the name of the embedded file. But I could name the exe the same as the wrapped file, so if the program can get the name of itself that'd work too.
Some of the wrapped files will be exes, and the others will be files meant to be run by an external program.
Edit: These files are being embedded with a .res file, they're not just concatenated to the end of the exe.
So you have a binary file embedded as a resource in an EXE, and you want to read the file?
Try something like this (very rough, look up functions on MSDN for proper parameters):
HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), type);
HGLOBAL hGlobal = LoadResource(NULL, hResource);
BYTE* pData = (BYTE*)LockResource(hGlobal);
int size = SizeofResource(NULL, hResource);
// ... do something with pData and size, eg write to disk ...
FreeResource(hGlobal); // done with data
You'll want to add some error checking in to that!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With