Using #include Directive with Windows Resource Compiler (80945)



The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) 3.0
  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Win32 Software Development Kit (SDK) 3.5
  • Microsoft Win32 Software Development Kit (SDK) 3.51
  • Microsoft Win32 Software Development Kit (SDK) 4.0

This article was previously published under Q80945

SUMMARY

The Windows Resource Compiler supports many standard C language preprocessor directives such as "#define" to define symbolic constants, and "#include" to include header and other resource files.

If an application developed for the Windows environment has more than one resource, each resource can be maintained in a separate file. Then, use the #include directive to direct the Resource Compiler to build all the resources into one output file. Using this technique prevents one resource file from becoming unmanageably large with an overwhelming number of resources.

It is important to note that the Resource Compiler treats files with the .C and .H extensions in a special manner. It assumes that a file with one of these two extensions does not contain resources. When a file has the .C or .H file extension, the Resource Compiler ignores all lines in the file except for preprocessor directives (#define, #include, and so forth). Therefore, a file that contains resources that is included in another resource file should not have the .C or .H file extension.

MORE INFORMATION

The following example demonstrates the implications of this situation. The MSG.H file has the following contents:
   /*
    * This header file defines message IDs for strings in the
    * stringtable resource. All source files can use this header file
    * to reference specific strings.
    */ 
   #define STRING1   1
   #define STRING2   2
   #define STRING3   3
				

The STRTABLE.RC file has the following contents:
   /*
    * This file defines the stringtable resource contents for this
    * application. It should be included in the application's resource
    * file. It requires definitions from the MSG.H header file.
    */ 
   STRINGTABLE
      {
      STRING1, "This is string 1."
      STRING2, "This is string 2."
      STRING3, "This is string 3."
      }
				

The APP.RC file has the following contents:
   /*
    * This is the "main" resource definition file for this
    * application. Among other things, it includes the stringtable
    * resource definition from other header files.
    */ 
   RESOURCE 1 (MENU)
   RESOURCE 2 (RAW DATA)
   ...

   #include "MSG.H"
   #include "STRTABLE.RC"
				

The Resource Compiler treats both MSG.H and STRTABLE.RC as header files. MSG.H does not include any resources; therefore, it can use the standard .H file extension. However, because STRTABLE.RC includes a resource (a STRINGTABLE), it cannot be named with a .C or .H file extension.

Files that contain resources can have any legal MS-DOS file extension other than .C and .H.

Modification Type:MajorLast Reviewed:3/6/1999
Keywords:KB80945