FIX: C2373 on getwchar/putwchar When Using UNICODE & __stdcall

Last reviewed: September 19, 1997
Article ID: Q155211
The information in this article applies to:
  • The C Run Time (CRT) included with: - Microsoft Visual C++, 32-bit Edition, version 4.2

SYMPTOMS

When you build a project, the Visual C++ 4.2 compiler generates the following errors:

   C:\MSDEV\INCLUDE\wchar.h(590): error C2373: 'getwchar': redefinition:
                                  different type modifiers
   C:\MSDEV\INCLUDE\wchar.h(592): error C2373: 'putwchar': redefinition:
                                  different type modifiers

The compiler errors are generated if the project does all of the following:

  1. Directly or indirectly includes the header file wchar.h.
2. Defines the preprocessor identifier _UNICODE. 3. Specifies the __stdcall or __fastcall calling convention.

The errors can also be generated for any AppWizard-generated MFC applications that define the _UNICODE preprocessor and use the __stdcall or __fastcall calling convention. To reproduce this problem, please see the More Information section below.

CAUSE

In Wchar.h, functions getwchar and putwchar are prototyped as follows on line 467 and line 469:

   _CRTIMP wint_t __cdecl getwchar(void);
   _CRTIMP wint_t __cdecl putwchar(wint_t);

There is also an inline version of these two functions defined in this file on line 491 and line 493.

   inline wint_t getwchar() { ... }
   inline wint_t putwchar() { ... }

Notice that the inline versions of getwchar and putwchar defined on line 491 and line 493 are not explicitly defined to use the __cdecl calling convention, which resolve the above compiler errors when the __stdcall or __fastcall calling convention is used.

RESOLUTION

If enabling _UNICODE is necessary to your application, work around this problem by doing the following:

Use the __cdecl calling convention instead of the __stdcall or the __fastcall calling convention.

Notice that the linker may generate error LNK2001 on the unresolved external symbol "_WinMain@16" when you build an MFC application with UNICODE support. This is because MFC UNICODE applications use wWinMain as the entry point. To solve this problem, in the Output category of the Link field in the Project Settings dialog box, set the Entry Point Symbol to wWinMainCRTStartup.

For additional information on the LNK2001 link error, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q125750
   TITLE     : PRB:Error LNK2001: '_WinMain@16': Unresolved External Symbol

-or-

Modify the header file Wchar.h. Change line 491 and 493 from the following:

   inline wint_t getwchar() { ... }
   inline wint_t putwchar() { ... }

to the following:

   inline wint_t __cdel getwchar() { ... }
   inline wint_t __cdel putwchar() { ... }

Modify the header file again if it is overwritten.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

MORE INFORMATION

Use the following steps to reproduce this problem:

  1. Generate an MFC application using the AppWizard and accept all the defaults.

  2. Modify the build settings as follows: a. Add the _UNICODE preprocessor definition under C/C++/General. b. Delete the _MBCS preprocessor definition under C/C++/General. c. Choose the __stdcall or __fastcall calling convention under

          C/C++/Code Generation.
    
    d. Build the application.

Keywords          : CLIss CRTIss vcbuglist420 vcfixlist500
Technology        : kbMfc
Version           : 4.2
Platform          : NT WINDOWS
Issue type        : kbbug
Solution Type     : kbfix


================================================================================


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