Not using TEXT() macro in code on VS 2017

How do we do not to use TEXT() macro in coding visual c++ source but instead opt to either Unicode or Ansi option in settings of build configuration on Visual Studio 2017?
Last edited on
The point of TEXT() is to try to make the code work correctly regardless of how it was built, but if you know your project will always be built in either Unicode or multi-byte configuration, you can skip it and just use normal strings:
 
CreateFile(L"unicode_filename.txt", /*...*/);

 
CreateFile("ansi_filename.txt", /*...*/);

Personally, I think it's better to ignore that nonsense and just use the version of the function you want:
1
2
CreateFileW(L"unicode_filename.txt", /*...*/);
CreateFileA("ansi_filename.txt", /*...*/);

Whenever possible you should use the Unicode versions, because the behavior of the ANSI version depends on the locale the user has configured, and that can change the behavior of your program in surprising ways.
helios’s answer is spot-on. Just joined to “+1” and “me too” because it was so good.
Whenever possible you should use the Unicode versions

MS suggests any new Windows apps should be coded using Unicode. ANSI "died" with Win98/ME years ago.
Topic archived. No new replies allowed.