How do I turn off Unicode in a VC++ project?
Asked Answered
P

6

76

I have a VC++ project in Visual Studio 2008.

It is defining the symbols for unicode on the compiler command line (/D "_UNICODE" /D "UNICODE"), even though I do not have this symbol turned on in the preprocessor section for the project.

alt text

As a result I am compiling against the Unicode versions of all the Win32 library functions, as opposed to the ANSI ones. For example in WinBase.h, there is:

#ifdef UNICODE
#define CreateFile  CreateFileW
#else
#define CreateFile  CreateFileA
#endif // !UNICODE

Where is the unicode being turned on in the VC++ project, how can I turn it off?

Petard answered 23/8, 2009 at 20:24 Comment(6)
Now for the real question: Why - for heaven's sake - would you ever hope to gain anything from disabling UNICODE support? This has got to be the very first time I ever saw anybody asking for help with entering failure mode.Nocturn
If you have legacy code to support? We have a bunch of libraries which use char/TCHAR interchanegably for example, from 15 years ago.Spermatophore
@IInspectable: Unicode support is not the same as moving char to wchar_t, which is Window's crappy way of doing "Unicode". Give me UTF-8 any day over some botched UTF-16 implementation.Cairistiona
@ThomasEding: On Windows, wchar_t is synonymous for Unicode/UTF-16LE encoding. Crappy or not, it is the native character encoding in Windows, exposed through the Windows API. If you wish to interface with it, you better learn to appreciate it. Incidentally, .NET strings use UTF-16 encoding as well. So does NTFS. Or Java strings.Nocturn
I'll use a C++ UTF-8 library when working with C++, thanks. Now my code works on Linux too. The wonders!Cairistiona
You can use a C++ UTF-8 library all you want, but you'll still have to convert those UTF-8 strings into UTF-16 strings in order to interface with the platform's native API. And so defining UNICODE helps to ensure that you do not goof up and accidentally pass a UTF-8 string (typed as char) to an API function that is expecting an ANSI string (also typed as char, very different from UTF-8). Note that, contrary to the expectations of some programmers, UTF-8 is not a valid ANSI code page on Windows. @thomasSemiprofessional
S
112

Have you tried: Project Properties - General - Project Defaults - Character Set?

See answers in this question for the differences between "Use Multi-Byte Character Set" and "Not Set" options: About the "Character set" option in visual studio 2010

Soong answered 23/8, 2009 at 20:30 Comment(3)
Thank you very much. This helped me a lot with a project I found and can not compile.Sadler
thanks again it saved my problem UNICODE by default is not nice move though.!Gustafsson
In Visual Studio 2019: Project Properties > Advanced > Character Set Set to Not Set or Use Multi-Byte Character Set.Whooper
M
21

Burgos has the right answer. Just to clarify, the Character Set should be changed to "Not Set".

Maryn answered 5/11, 2009 at 4:47 Comment(1)
No, it should not. "Not Set" amounts to inheriting that setting, from some default. In other words: The code may still be compiled with Unicode support. This is like answering the question "How do I make sure this light is off?" with "Do NOT touch the light switch!" (which, indeed, produces the desired result in 50% of the cases).Nocturn
C
12

From VS2019 Project Properties - Advanced - Advanced Properties - Character Set enter image description here

Also if there is _UNICODE;UNICODE Preprocessors Definitions remove them. Project Properties - C/C++ - Preprocessor - Preprocessor Definition enter image description here

Cerate answered 9/1, 2020 at 16:33 Comment(0)
K
9

project properities -> configuration properities -> general -> charater set

Kayseri answered 23/8, 2009 at 20:30 Comment(0)
R
5

For whatever reason, I noticed that setting to unicode for "All Configurations" did not actually apply to all configurations.

Picture: Setting Configuragion In IDE

To confirm this, I would open the .vcxproj and confirm the correct token is in all 4 locations. In this photo, I am using unicode. So the string I am looking for is "Unicode". For you, you likely want it to say "MultiByte".

Picture: Confirming changes in configuration file

Rhetorical answered 24/7, 2017 at 16:45 Comment(1)
don't post code or text as image. Copy/paste the text hereAtalayah
H
-5

you can go to project properties --> configuration properties --> General -->Project default and there change the "Character set" from "Unicode" to "Not set".

Hortensiahorter answered 23/6, 2015 at 21:42 Comment(1)
Any reason you stop by, and copy a 6 year old answer without contributing anything of value? Without attributing the source of information, of course.Nocturn

© 2022 - 2024 — McMap. All rights reserved.