Converting A File Into Bytes And Re Creating It

Hi there, I would like to take some files I have, a dll and a inf file, and convert them into a char array, binary. After I have done that I would like to put them in my header file for example and than create file and write file the bytes into a dll or inf file that I had before. If there is an easier way through resources, I would be glad if someone could point me in the right direction to achieve my goal, that would be good as well.
Last edited on
everything is byte array already, so just open any file you want, modify and store like you would normally do.
I would like to put them in my header file for example ...

Convert files of any types to a file with c strings
http://stackoverflow.com/questions/1710376/convert-files-of-any-types-to-a-file-with-c-strings

Andy

PS Alternative approach on Linux

Embedding a File in an Executable, aka Hello World, Version 5967
http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
Last edited on
I followed what andywestken recommended and was able to create the files from bytes, but when I tried to do create file and writefile my dll, it had a md5 signature and the signature is gone. How do I create it from bytes yet keep the signature. Or do I have to extract it?
You can add any file as a resource. If you use VS, select "Import" in the Add Resource dialog.

To load the resource, call FindResource() and then LoadResource().
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648006%28v=vs.85%29.aspx

To get the size of the resource, in bytes, call SizeOfResource().
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648048%28v=vs.85%29.aspx

To read the resource/binary data, call LockResource().
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648047%28v=vs.85%29.aspx
So basically what your recommending ahcfan, is what andy recommended. Taking bytes and writing to a create-file. I can do all this but I want to keep my signature of my dll, how would I be able to do this?
You asked in your post if there was an easier way using resources and I just posted the one way I know of. If you make a byte-by-byte copy of the original file then I figure the MD5 hash should be identical.
So the code
1
2
HRSRC hRes = ::FindResource(hInstance, MAKEINTRESOURCE(IDR_DRIVERRRRRR1), RT_RCDATA);
if (hRes == 0) {cout << "failed" << endl;}

fails with 0, and I managed to get my dll into a resource like this
http://i.imgur.com/Him1vFM.png
Last edited on
Try calling GetLastError() to see why it fails.
1813 (0x715)
The specified resource type cannot be found in the image file.

o-o How am I supposed to add the dll resource to look as if it were just another file.
Bump
wow what I great forum, great answers on every question, help me a lot
Topic archived. No new replies allowed.