How can I read a compiled resource (.res) file in C #?

I have a compiled resource file (.res). I need to read it in C # so that I can change it programmatically. note that this is not a .resx or .rc file; The file is compiled, not text.

So far, I have been trying to browse LoadLibrary, LoadResource, etc. in the Win32 API, but it seems that these functions only work with executable files (.exe, .dll), not resource files.

I tried uploading the file using BinaryReader , but of course I cannot understand the meaning of the resulting byte array. I was thinking of trying to use Marshal.PtrToStructure , but I have no idea about the structure of the res file. I have a RESOURCEHEADER structure, but I could not figure out how to use it (I admit that I have very few relatives, code).

Can someone help me figure out how to successfully read and update version information in a .res file?

+6
source share
1 answer

Very good question; I also could not find a good answer using existing functions. Fortunately, it seems that the RES file format is pretty simple and 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 corresponding fields. Remember that the title of the resource aligns to DWORD.

My other suggestions would be to use LoadLibraryEx and see if you can somehow load the RES file as a data file. But it looks like you've already tried it. If you succeed, you may find this topic interesting - this is 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. I loaded RC.EXE into Dependency Walker to find out if it uses any interesting APIs to create RES files. I did not find, so I can only assume that RC.EXE directly writes RES files.

+3
source

Source: https://habr.com/ru/post/900620/


All Articles