A 32 bit resource file is comprised as follows:
File header Resource 1 Padding Resource 2 Padding - - - Resource N Padding
The File header is a "pseudo-resource" that identifies the file as a 32 bit resource file (rather than 16 bit). This is a 32 byte structure, the first 8 bytes of which are $00, $00, $00, $00, $20, $00, $00, $00.
Each resource is made up of a variable length header record followed the resource data. The variable length header is made up of the following fields:
DataSize: DWORD; // size of resource data (excl end padding) HeaderSize: DWORD; // size of resource data header Type: Unicode or Ordinal; // type of resource Name: Unicode or Ordinal; // name of resource [Padding: Word]; // optional padding to DWORD boundary DataVersion: DWORD; // version of the data resource MemoryFlags: Word; // describes the state of the resource LanguageId: Word; // language for the resource Version: DWORD; // user defined resource version Characteristics: DWORD; // user defined info about resource
Here is a description of the resource header fields.
Field | Description |
---|---|
DataSize | The size of the resource data that follows the header in bytes, excluding any padding that follows that data. |
HeaderSize | The size of the resource header record, including DataSize and HeaderSize fields. |
Type | Variable length field that specifies the resource type either as an ordinal value or as a Unicode string. If the first Word of Type is $FFFF the second word is the ordinal value. Otherwise the value is a zero terminated Unicode string. Ordinals less than 255 are reserved by Windows. See below for a list of predefined resource types. |
Name | Variable length field that specifies the resource name either as an ordinal value or as a Unicode string. If the first Word of Name is $FFFF the second word is the ordinal value. Otherwise the value is a zero terminated Unicode string. Note that some resources may not have string names - for example string tables must have ordinal resource ids, all version information resource I have seen have resource id 1 and the resource id of an XP manifest is significant to the system. |
[Padding] | Optional padding to ensure the following fields begin on a DWORD boundary. |
DataVersion | Determines the format of the information within the resource header that follows. Often zero. Reserved for use by the system. |
MemoryFlags | A bitmask of flags that describe the state of the resource.
See the RES_MF_XXX flags described in the Constants section
for details. |
LanguageID | Specifies the language used for any strings in the resource or 0 if language neutral. Bits 0-9 of this Word contain the primary language ID while bits 11-15 contain the sub language ID (dialect or variation). |
Version | Stores custom version information - sometimes used by the resource compiler. Ignored by the system and stripped out on linking into the application. |
Characteristics | Stores custom information about the resource - sometimes used by the resource compiler. Ignored by the system and stripped out on linking into the application. |
The following table lists the predefined resource types known at the time of
writing. RT_HTML
and RT_MANIFEST
are not defined in
Delphi's Windows unit.
Resource Name | Ordinal value | Description |
---|---|---|
RT_ACCELERATOR |
9 |
Accelerator table |
RT_ANICURSOR |
21 |
Animated cursor |
RT_ANIICON |
22 |
Animated icon |
RT_BITMAP |
2 |
Bitmap resource |
RT_CURSOR |
1 |
Hardware dependent cursor resource |
RT_DIALOG |
5 |
Dialog box |
RT_DLGINCLUDE |
17 |
Allows a resource editing tool to associate a string with
an .rc file. Typically, the string is the name of the header file that provides
symbolic names. The resource compiler parses the string but otherwise ignores
the value. For example:
/* file foo.dlg */ 1 DLGINCLUDE "foo.h" |
RT_FONT |
8 |
Font resource |
RT_FONTDIR |
7 |
Font directory resource |
RT_GROUP_CURSOR |
12 |
Hardware independent cursor resource - refers to RT_CURSOR |
RT_GROUP_ICON |
14 |
Hardware independent icon resource - refers to RT_ICON |
RT_HTML |
23 |
HTML "Documents": .html, .gif, .css code etc. |
RT_ICON |
3 |
Hardware dependant icon resource |
RT_MANIFEST |
24 |
Side-by-side assembly XML manifest (Windows XP) |
RT_MENU |
4 |
Menu resource |
RT_MESSAGETABLE |
11 |
Message table entry |
RT_PLUGPLAY |
19 |
Plug and play resource |
RT_RCDATA |
10 |
Application or user defined resource - raw data |
RT_STRING |
6 |
String table entry |
RT_VERSION |
16 |
Version information |
RT_VXD |
20 |
VXD |
Note that the RT_XXX
constants are not assigned the ordinal values
directly but are set using MakeIntResource. So, for example, RT_VERSION
= MakeIntResource(16)
.
Each new resource starts on a DWORD boundary, so there may be padding bytes following the end of each resource if the resource data is not a multiple of 4 bytes in length.
The format of the actual resource data depends on the resource type. We do not go into that detail here since this code only provides high-level access to resources in a file and deals only with raw data.
Various documents were used in creating this document. Key documents were:
The original work in this document is copyright © Peter Johnson, 2004. http://www.delphidabbler.com/. Please contact the author via the web site for permission to republish.