none
Turn off /D UNICODE and /D _UNICODE in Visual Studio 2008 Professional

    Question

  •  

    I'm trying to compile some older code that was compiled without the UNICODE or _UNICODE preprocessor flags.  Unfortunately, it was also written without TCHARs so I have a lot of code that looks like this:

     

    Code Block

    char szPath[MAX_PATH];

    GetModuleFileName (Module, szPath, MAX_PATH);

     

     

     

    I realize the better way to fix this is change the code to use TCHARs but this is old code who's life is about to end and I'm just trying to get it compiled to run a couple tests. 

     

    Is there a way to turn off the UNICODE preprocessor flags?  I've been going through the project and solution settings but the only thing I found was a setting to undefine preprocessor definitions and that didn't work.

     

    Thanks for the help!

     

    Tuesday, December 11, 2007 2:49 PM

Answers

  • To turn off UNICODE preprocessor flags, you can try the following steps:

    1. Open your project in VS2005;

    2. Right click the project in Solution Explorer and click Properties;

    3. Select "Configuration Properties"-> "General", select "Character Set" and change the current value to "Use Multi-Byte Character Set".

     

    Hope this helps.

     

    Sincerely,

    Charles Wang

    Thursday, December 13, 2007 6:44 AM
    Moderator

All replies

  • To turn off UNICODE preprocessor flags, you can try the following steps:

    1. Open your project in VS2005;

    2. Right click the project in Solution Explorer and click Properties;

    3. Select "Configuration Properties"-> "General", select "Character Set" and change the current value to "Use Multi-Byte Character Set".

     

    Hope this helps.

     

    Sincerely,

    Charles Wang

    Thursday, December 13, 2007 6:44 AM
    Moderator
  • I have a similar problem using Visual C++ 10 Express, but the suggestion above unfortunately doesn’t seem to work for me.

    I’ve changed the settings of Project Properties -> Configuration Properties -> General -> Character Set    to “Not Set” and also to “Use Multi Byte Character Set”, but the compiler still assumes Unicode (I get hundreds of pointer errors when compiling).

    Looking at the command line using Project Properties -> Configuration Properties -> C/C++ -> Command Line    … it has   /D “UNICODE”  and /D “_UNICODE” appearing, irrespective of the selected “Character Set”:

    /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS

    As a workaround I undefine UNICODE and _UNICODE by adding them into Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Undefine Preprocessor Defintions.

    Now looking at the command line I see the Unicode directives defined, then they are undefined again as expected:

    /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /U"UNICODE" /U"_UNICODE" /Gm /EHsc /RTC1 /GS

    While the workaround works fine and I can compile without errors, I get a couple of expected warnings:

    Command line warning D9025: overriding '/DUNICODE' with '/UUNICODE'

    Command line warning D9025: overriding '/D_UNICODE' with '/U_UNICODE'

    This is OK, but is there a way to actually switch off the Unicode directives rather than have to undefine them? Many thanks.

    Saturday, August 21, 2010 8:58 AM
  • You have already tried all the settings dialogs I would have suggested, so I would edit the .vcproj file in Notepad and search for UNICODE and see if you can find and delete where it originally get set.
     
    -- David
     

    Efficiently access this forum with newsreaders like WLM, Thunderbird, and Forte Agent: http://communitybridge.codeplex.com
    Saturday, August 21, 2010 2:56 PM
  • Yep, I did hand-edit the .vcxproj file and removed all traces of 'Unicode' - but the project is still convinced I want Unicode defined - Unicode still appears in the /D of the command line and the warnings are still generated. Well wierd, I wonder if this could (dare I say it) be a bug?

    Steve

    Monday, August 23, 2010 6:36 PM
  • Sorry to revive an old thread, but I have the same issue as stevie-r-g; no matter what I do, Visual Studio assumes I want Unicode. Like you, I've added "_UNICODE;UNICODE" to the "Undefine Preprocessor Definitions" which solves the issue temporarily (having already set the project properties Character Set to "Not Set" and "Multibyte" (neither of which worked)). It just seems like a bit of a nasty cludge though.

    Any other solutions?

    Thanks :)

    Seb

    Wednesday, November 23, 2011 3:19 PM
  • Try CTRL+F5 "Start without debugging"

    Regards.

    Sunday, March 11, 2012 6:49 PM