C2002: invalid wide-character constant after moving to July CTP of VS2005 Beta Team System Edtion

The following code fragment from a header file compiled alright with Visual Studio 2005 Team System Edition Beta 2 (from DVD), but when I installed the July 2005 edition, I now get a compiler error:

C2002: invalid wide-character constant

Any sugestions as to what could be the problem   Thank you.

--------------------------------------------------------------


#ifdef
_DEBUG

#pragma comment (lib, _DNT("AcGe17d.lib") )   // Error points to this line

#else

#pragma comment (lib, _DNT("AcGe17.lib") )

#endif
---------------------------------------------




Answer this question

C2002: invalid wide-character constant after moving to July CTP of VS2005 Beta Team System Edtion

  • JayKay

    Could you use the /P compiler option (generates a preprocessed version of the file) and see what does it get resolved to

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Henk van Andel

    Good morning Ayman,

    I was able to reproduce the error by creating a new VS2005 C++ console project and then simply pasting the definition of _DNT and the #pragma into the file containing main().  I would like to send you the ZIP'ped project (only 4Kb) but there doesn't seem to be an option to attach files in this forum.  If you reply to my Yahoo.com address (user id is HGOHEL) then I can send it to you.

    Thank you.


  • BarBQ

    Hello,
     I was able to reproduce the error by just doing (cl a.cpp):
      
    //a.cpp 
    #pragma comment (lib, L"AcGe17.lib" )
     void main(){}

    output:
    a.cpp(1) : error C2002: invalid wide-character constant

    I talked to the compiler front end folks and they indicated that this is by design that wide charcaters are not accepted in #pragma comment. However, you can use escape characters like /u.

    If you feel strongly about allowing "L" in such pragmas, please feel free to log a suggestion at http://lab.msdn.microsoft.com/productfeedback/default.aspx

    Thanks,
      Ayman Shoukry
      VC++ Team



  • Eric-Jan

    Compiling the following (t.cpp):
    #ifdef _DEBUG
    #pragma comment (lib, _DNT("AcGe17d.lib") )   // Error points to this line
    #else
    #pragma comment (lib, _DNT("AcGe17.lib") )
    #endif

    I am just getting the warning:
    t.cpp(4) : warning C4083: expected 'string'; found identifier '_DNT'

    Could you please include the compiler switches or exact compilationcommand line used

    Thanks,
      Ayman Shoukry
      VC++ Team


  • danglen

    Ayman,

    To get past the issue for now, I simply took out the macros and coded the string simply in quotes and that seems to work.

    I'll try your suggestion and compile the code in a new project/solution and post the outcome here.

    Thanks.


  • Dido44538

    Ayman, thank you for looking into this.

    _DNT is defined in an include file as:

    #ifndef _DNT

    #define _DNT(x) _T(x)

    #endif // _DNT

    In the compilation command line shown below I've removed a bunch of /I include directories and /D defines that aren't relevant:

    /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_VC80_UPGRADE=0x0710" /D "_WINDLL" /D "_AFXDLL" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp".\Debug/AeccWin32Utils.pch" /Fo".\Debug/" /Fd".\Debug/" /W4 /WX /nologo /c /ZI /errorReport:prompt

    I was able to get past the errors by removing the macro and simply leaving the string in quotes.  However, this code compiles normally under Visual Studio .NET 2003, and it did in Beta 2 as well.



  • Groenewald

    I put the following code into one file (x.cpp) and compiled it:

    //x.cpp
    #ifndef _DNT
    #define _DNT(x) _T(x)
    #endif // _DNT
    #ifdef _DEBUG
    #pragma comment (lib, _DNT("AcGe17d.lib") )   // Error points to this line
    #else
    #pragma comment (lib, _DNT("AcGe17.lib") )
    #endif

    Compilation command:
    cl /Od /D "_DEBUG" /D "WIN32" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /c /MDd /W4 /nologo /c /ZI /errorReport:prompt x.cpp

    I still can't reproduce the error.
    I might be missing somthing. Could you put a small sample case that reproduces the error as well as trying the above sample and see if you are still getting C2002.

    Thanks,
      Ayman Shoukry
      VC++ Team



  • Vaibhav_Patel

    I see: _DNT(x) gets converted to _T(x) which resolves to __T(x) which resolves to L ## x, which causes the error.

    However, this also causes a problem, and I don't see why:



    #define _DNX(x) x


    #ifdef _DEBUG

    #define AEC_LIB_TAG AEC_PRODUCT_VER_ID_STRING _DNX("d.lib")

    #else

    #define AEC_LIB_TAG AEC_PRODUCT_VER_ID_STRING _DNX(".lib")

    #endif

    #pragma comment( lib, _DNX("AecBase") AEC_PRODUCT_VER_ID_STRING /*_DNX("D.lib")*/ )

     


     
    Using the previously definted AEC_PRODUCT_VER_ID_STRING results in the same C2002, but replacing it with _DNX("D.lib") doesn't...that seems inconsistent.  Again, this is code that compiled with Beta 2, but not with July 2005 CTP.  Comments



  • Alex Jimenez

    Ayman,

    While discussing this with a coworker, we finally stumbled upon the problem...in my previous example, the concatenation of AEC_PRODUCT_VER_ID_STRING was causing the error, because it was defined as _T("50")...once we change that to use the _DNX macro just like the _DNX("D.lib") it should be OK.


  • C2002: invalid wide-character constant after moving to July CTP of VS2005 Beta Team System Edtion