The new vbAccelerator Site - more VB and .NET Code and Controls

Articles

&nbsp

Using RC.EXE

 
Techniques for coding real-world components in VB
 
Somehow I never seem to have enough storage space for all my files.

Overview

This article explains how to use the Resource Compiler (RC.EXE) to create resource files (.RES).

  1. About the Resource Compiler
  2. String Resources
  3. Binary Resources
  4. RC.EXE Options
About the Resource Compiler (RC.EXE)

The Resource Compiler compiles the resource definition file and the resource files (binary files such as icon, bitmap, and cursor files) into a binary resource (.RES) file. The .RES file can then be included in any VB project, and once the VB project is compiled, the resources are accessible to Win32 API functions as well as the standard VB LoadResString, LoadResPicture and LoadResData functions.

The Resource Compiler itself consists of two files:

  1. RC.EXE
  2. RCDLL.DLL
These files come in the \Tools directory of Enterprise Editions of VB; if you don't have that then you can download the files by downloading the VB5 Resource Add-In from the Visual Basic Owner's Area at MSDN.

Resources can be divided into two groups:
  • String resources (text strings such as "vbAccelerator").
  • Binary resources (icons, bitmaps, cursors, sounds, video, and so forth).
2. String Resources

String resources are stored in a string table in the resource definition file.

Syntax

STRINGTABLE [load-option] [mem-option]
BEGIN
	stringID string
	.
    	.
    	.
END
The STRINGTABLE statement defines one or more string resources for an application. String resources are simply null-terminated ASCII strings that can be loaded when needed from the executable file, using the LoadResString function.

Parameters
  1. load-option. Specifies when the resource is to be loaded. This optional parameter must be one of the following options:
    • PRELOAD
      Resource is loaded immediately.
    • LOADONCALL
      (Default) Resource is loaded when called.
  2. mem-option. Specifies whether the resource is fixed or can be moved and whether or not can be discarded. This optional parameter can be one of the following options:
    • FIXED
      Resource remains at a fixed memory location.
    • MOVEABLE
      Resource can be moved if necessary in order to compact memory.
    • DISCARDABLE
      Resource can be discarded if no longer needed.
  3. stringID. Specifies an integer value that identifies the resource.
  4. string. Specifies one or more ASCII strings, enclosed in double quotation marks. The string must be no longer than 255 characters and must occupy a single line in the source file.
Grouping strings in separate segments allows all related strings to be read once in a single reading and discarded together. When possible, you should be able to move and discard the table. The Resource Compiler allocates 16 strings per segment and uses the identifier value to determine which segment will contain the string. Strings with the same upper-12 bits in their identifiers are placed in the same segment.

Example
The following example demonstrates the STRINGTABLE statement:
#define IDS_HELLO    1
#define IDS_GOODBYE  2

STRINGTABLE
BEGIN
    IDS_HELLO,   "Hello"
    IDS_GOODBYE, "Goodbye"
END 
3. Binary Resources

Binary resources are not stored in the resource definition file. The resource definition file includes only a pointer to the files containing the binary resources, for example, icon (.ICO), bitmap (.BMP), cursor (.CUR), sound (.WAV), and video (.AVI) files.

This pointer is called a Single-Line Statement in the resource definition file.

Syntax

nameID keyword [load-option] [mem-option] filename
Parameters
  1. nameID. Specifies either a name or an integer value identifying the resource. This ID has to be unique for every category specified by the keyword. In the category ICON the ID 0 is reserved for the Visual Basic icon. Therefore you'll have to start ID for ICONS at 1.
  2. keyword. Specifies the type of file. The parameter must be one of the following options:
    • BITMAP
      Defines a bitmap (.BMP)
    • CURSOR
      Defines a cursor (.CUR)
    • ICON
      Defines an icon (.ICO)
    • SOUND
      Defines a wave file (.WAV)
    • VIDEO
      Defines a video file (.AVI)
  3. load-option. Specifies when the resource is to be loaded. The parameter must be one of the following options:
    • PRELOAD>
      Resource is loaded immediately.
    • LOADONCALL
      (Default) Resource is loaded when called.
  4. mem-option. Specifies whether the resource is fixed or can be moved and whether it can be discarded. The parameter must be one of the following options:
    • FIXED
      Resource remains at a fixed memory location.
    • MOVEABLE
      Resource can be moved if necessary in order to compact memory.
    • DISCARDABLE
      Resource can be discarded if no longer needed.
    The default for binary resources is MOVEABLE.
  5. filename. Specifies the name of the file that contains the resource. The name must be a valid filename; it must be a full path if the file is not in the current working directory. The path can be either a quoted or non-quoted string.
Example
The following example specifies two bitmap resources:
disk1   BITMAP disk.bmp
12      BITMAP PRELOAD diskette.bmp
4. RC.EXE Options

To start the Resource Compiler, use the rc command.

Syntax

rc /r [options] definition-file
Parameters
  • /r
    This parameter specifies that the .RC file will only be compiled, not linked to any executable (required for use with VB)
  • options
    You can use the following options with the rc command:
    • /?
      Displays a list of rc command-line options.
    • /fo newname
      Uses newname for the name of the .RES file.
  • definition-file
    The definition-file parameter specifies the name of the resource definition file (.RC) that contains the names, types, filenames, and descriptions of the resources to be compiled.
Example
RC /r /fo TEST32.RES TEST.RC
Note:
You have to close your Visual Basic project or remove the .RES file from your project when you recreate the resource file.




TopBack to top
ArticlesBack to Articles

&nbsp
 

About  Contribute  Send Feedback  Privacy

Copyright © 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 1 November 1999