I've got a compiled resource file (.res). I need to read it, in C#, so that I can modify it programatically. note that this is not a .resx file or .rc file; the file is compiled, not text-based.
So far I tried looking at LoadLibrary, LoadResource, etc. in the Win32 API, but it seems that these functions only work on executables (.exe, .dll), and not resource files.
I've tried loading the file with BinaryReader, but of course I can't make much sense of the resultant byte array. I thought of trying to use Marshal.PtrToStructure but I haven't got an idea what the structure of a res file is. I've got the structure of the RESOURCEHEADER, but I couldn't understand how to use it (I admit I've got very little native-code experience).
Could anybody please help me figure out how to successfully read and update the version info in the .res file?
You can open resource script files by right-clicking the . rc file in Solution Explorer, selecting Open with and choosing Source Code (Text) Editor.
What is a Resource Script. The resource compiler compiles a special type of file known as a Resource Script. Resource scripts contain GUI data, and, when compiled, can be linked into a program. The program then can access the data contained in the resource script.
Resources can contain data in a number of forms, including strings, images, and persisted objects. (To write persisted objects to a resource file, the objects must be serializable.) Storing your data in a resource file enables you to change the data without recompiling your entire app.
Very good question; I couldn't find a good answer using existing functions either. Fortunately, it seems that the RES file format is relatively simple, and is documented here:
http://msdn.microsoft.com/en-us/library/ms648007(VS.85).aspx
You should be able to scan the RES file for the version resource, and then update the appropriate fields. Remember that the resource header is DWORD-aligned.
My only other suggestions would be to use LoadLibraryEx and see if you can load the RES file as a datafile somehow. But it sounds like you've already tried that. If you did succeed though, you might find this topic interesting - it's an example of how to copy resources between two modules:
http://msdn.microsoft.com/en-us/library/ms648008(VS.85).aspx
I doubt it will work though. I loaded RC.EXE in Dependency Walker to see if it was using any interesting APIs for building RES files. I did not find any, so I can only assume that RC.EXE directly writes out the RES files.
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