windowsvisual-studioembedded-resourceresource-file

How do windows resource files work?


I want to embed image files in my windows executable. The easiest way I have found is to use windows resource files.

I generated resource.rc and resource.h using visual studio. Next step is to call these resources in my source code. What exactly is happening behind the hood with resource files?

Opening the .rc file in a text editor shows me the resource name and a path to the actual image file. Opening the resources in visual studio shows huge character arrays.

Where are those character arrays being stored? And when are they being generated?


Solution

  • The secret is very simple. It is based on the way information is stored in object files (like COFF) and
    PE files (exe and dll). These files have sections for storing data - which includes binary data like images and sound files. Resource files take advantage of this. When your resource compiler compiles your resource file, it simply stores the binary files (images, sound, icons, movies, animation,etc) and the other data (such as menus, dialog boxes, accelerators, string table) in the compiled resource file and pass this file to the linker. The linker then chooses the appropriate section to place it in the output file.