none
Visual C++ isn't recognizing wchar_t as a native type

    Question

  • I created an empty project with Visual C++ but realized afterwards that I really wanted a win32 project instead.  I created a win32 project and copied all of the code to the new project.  Whereas all of the code in the first project compiled error free, when I compile the new project, I get about 200 errors all saying roughly the same thing: "cannot convert const char to const wchar_t"

    It took a while to track down the source of the problem, but I found it in a directory I had included. Here's the relevant snippet of the code:

     

     

    #if defined(wchar_t) //this is if the compiler considers wchar_t as native type
    #define wchar_t unsigned short
    #endif
    
    Here's my problem, in the first project I created, wchar_t was defined and that preprocessor block was active, but in the new project it is not defined.  I went to the Project properties window and wchar_t IS set as a native type, so I'm not sure why Visual C++ isn't recognizing it.  If anyone has any thoughts about why this error is happening, I would greatly appreciate it.  Thanks!

     

     


    • Edited by longjetty7 Wednesday, June 29, 2011 6:32 PM
    Wednesday, June 29, 2011 5:44 AM

Answers

  • Thanks for the help guys.  As it turns out, the problem was that I was using the unicode character set.  I changed the project properties to use no set at all and that ended up making inactive most of that header file that was giving me problems.  I'm not sure what implications that will have for my project but at least those errors went away.
    • Marked as answer by Rob Pan Thursday, July 07, 2011 2:57 AM
    Wednesday, June 29, 2011 7:34 PM

All replies

  • You can change your project to compile on Unicode. Then,the preprocessor block will active.

    You can change the following property.

    Project -> Properties- > Configuration Properties-> General-> Project Defaults-> Use Unicode Character Set


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/
    Wednesday, June 29, 2011 6:14 AM
  • Enabling `wchar_t' as a native type does not define it as a macro, no more than `int' is a macro, and consequently its presence cannot be determined directly with use of the preprocessor. If you want to check whether `wchar_t' exists, regardless of macro or native type, use `#if defined(_WCHAR_T_DEFINED)' as documented here.

    Wednesday, June 29, 2011 10:47 AM
  • Thanks for the help guys.  As it turns out, the problem was that I was using the unicode character set.  I changed the project properties to use no set at all and that ended up making inactive most of that header file that was giving me problems.  I'm not sure what implications that will have for my project but at least those errors went away.
    • Marked as answer by Rob Pan Thursday, July 07, 2011 2:57 AM
    Wednesday, June 29, 2011 7:34 PM