Resource Compiler (RC.EXE)
The Resource Compiler (RC) is a command-line tool that reads resource script files (.rc) and converts them into binary resource files (.res). These binary files can then be linked into an executable program or dynamic-link library (DLL) by the linker.
Purpose
RC is used to compile resources such as:
- Icons (
.ico) - Bitmaps (
.bmp) - Dialog boxes (
DLGdirectives) - Menus (
MENUdirectives) - String tables (
STRINGTABLEdirectives) - Version information (
VERSIONINFOdirectives) - Custom resources
Syntax
The basic syntax for RC is:
rc [options] /fo output_file resource_file(s)
Common Options
Here are some of the most commonly used options for the RC tool:
/f[e|o|p]: Specifies the file format for the output resource file./fe: Produces a .res file suitable for linking with 32-bit Microsoft Win32 compilers./fo: Produces a .res file suitable for linking with 16-bit Microsoft compilers. (Less common now)/fp: Produces a portable executable (PE) .res file. This is the default behavior for modern SDKs.
/fo <output_file>: Specifies the name of the output resource file. If omitted, the output file will have the same base name as the first input resource file but with a.resextension./i <path>: Adds a directory to the search path for include files specified in the resource script. Can be specified multiple times./d <macro[=value]>: Defines a preprocessor macro. Useful for conditional compilation within resource scripts./v: Enables verbose output, showing more details about the compilation process./w[0-4]: Sets the warning level./w0suppresses all warnings./x: Ignores the default system include paths.
Example Usage
Compiling a simple resource script:
rc /fo MyResources.res /i "c:\myproject\resources" MyProject.rc
This command compiles MyProject.rc, looks for include files in c:\myproject\resources, and outputs the compiled resources to MyResources.res.
Defining a macro during compilation:
rc /d DEBUG_MODE=1 /fo App.res App.rc
Resource Script (.rc) Files
Resource scripts are text files that describe the resources to be included in an application. They use a C-like syntax and can include directives to embed or reference resource files and define resource types.
Common Resource Types in .rc files:
ACCELERATOR: Defines keyboard accelerators.BITMAP: Embeds a bitmap file.CURSOR: Embeds a cursor file.DIALOG: Defines a dialog box template.FONT: Specifies font information.GROUP_CURSOR: Embeds a cursor group file.GROUP_ICON: Embeds an icon group file.ICON: Embeds an icon file.MENU: Defines a menu template.RCDATA: Embeds custom binary data.STRINGTABLE: Defines string resources.VERSIONINFO: Specifies version information for the application.
Example of a simple .rc file snippet:
#include <windows.h>
// Icon resource
MAINICON ICON "appicon.ico"
// String table
STRINGTABLE
BEGIN
IDS_APPNAME "My Wonderful Application"
IDS_ABOUTBOX "About My Wonderful Application"
END
// Dialog box definition
ABOUT_DIALOG DIALOGEX 0, 0, 200, 100
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "MS Sans Serif"
{
DEFPUSHBUTTON "OK", IDOK, 140, 80, 50, 14
LTEXT "My Wonderful Application v1.0", IDC_STATIC_VERSION, 5, 5, 190, 20
}