PRB: C2632 Caused by Including WINDOWS.H First

Last reviewed: July 22, 1997
Article ID: Q113062
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft C/C++ version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

Compiling a source file that explicitly includes WINDOWS.H followed by a Microsoft Foundation Classes (MFC) header file such as AFX.H may produce errors such as:

   c2632 'long' followed by 'long' is illegal

CAUSE

This error occurs as a result of MFC using STRICT type checking by default. STRICT type checking is not used in WINDOWS.H unless you define STRICT as a preprocessor symbol before including the header file.

Specifically, WINDOWS.H has the following statement:

   #ifdef STRICT
   typedef signed long LONG;
   #else
   #define LONG long
   #endif

AFX.H has this statement:

   typedef long LONG;   // 32-bit signed number

As you can see, if STRICT type checking is not used and WINDOWS.H is included before AFX.H, the typedef statement in AFX.H becomes the following (after preprocessing):

   typedef long long;   // 32-bit signed number

The typedef statement is used to create another name for an existing data type. Because this statement has not specified a different name for the long data type, it is disallowed by the compiler.

RESOLUTION

Include WINDOWS.H after the MFC header files or not at all. AFXWIN.H automatically includes WINDOWS.H, so it is normally not necessary to explicitly include it in your source code.

Another way to avoid this error is to define STRICT as a preprocessor symbol before including WINDOWS.H. This will ensure that LONG is type defined as signed long rather than simply long.

MORE INFORMATION

MFC Technical Note 12 "Using Windows 3.1 Robustness Features" contains additional information on STRICT type checking and other Windows 3.1 robustness features.

Sample Code

/* Compile options needed:  /D_WINDOWS */

/*
#define STRICT    // Remove comments from this line to avoid errors.
*/

#include <windows.h> // Or, reverse order of these statements.
#include <afx.h>


Additional reference words: 7.00 1.00 1.50 2.00 2.50 technote tech note
KBCategory: kbprg kbprb
KBSubcategory: MfcMisc
Keywords : kb16bitonly
Technology : kbMfc


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 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.