PRB: Resource Compiler Error RW2001 Generated by #pragma

Last reviewed: July 17, 1997
Article ID: Q94571
3.00 3.10 3.11 | 3.10
MS-DOS         | WINDOWS NT
kbtool kbfasttip kbprb

The information in this article applies to:

  • Microsoft Windows Resource Compiler, versions 3.0 and 3.11
  • Microsoft Windows 32 Resource Compiler, version 3.1

SYMPTOMS

An attempt to process a resource command (.RC) file with the Microsoft Windows Resource Compiler or the Microsoft Windows 32 Resource Compiler fails and the compiler generates the following error message:

   error RW2001 : Invalid directive in preprocessed RC file

CAUSE

The RC file contains a #pragma directive.

RESOLUTION

Use the #ifndef preprocessor directive with the RC_INVOKED constant that the Resource Compiler defines when it processes an include file. Place the #pragma directive inside a block of code that is not processed when the RC_INVOKED constant is defined. Code in the block is processed only by the C/C++ compiler and not by the Resource Compiler. The following sample code demonstrates this technique:

   #ifndef RC_INVOKED
   #pragma pack(2)  // C/C++ only, ignored by Resource Compiler
   #endif

MORE INFORMATION

The #pragma preprocessor directive has no meaning in an .RC file. The

#include preprocessor directive is used frequently in an .RC file to
include a header file (either a project-based custom header file or a standard header file provided by Microsoft with one of its products). Some of these include files contain the #pragma directive. Because a header file can include one or more other header files, the file that contains the offending #pragma directive may not be immediately obvious.

Under most circumstances, an application includes only the header files that define its symbols. However, many of the system include files provided with Microsoft C/C++ version 7.0 contain the #pragma directive. Many of these files do not include the RC_INVOKED test because they are not intended for use with the Resource Compiler. Header files designed for use with the Resource Compiler (such as WINDOWS.H) do not cause this error.

The #ifndef RC_INVOKED technique can control including header files in project-based header files.


Additional reference words: 7.00 1.00 3.11 3.10
KBCategory: kbtool kbfasttip kbprb
KBSubcategory: TlsRc
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.