Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert a Visual Studio project from using wide strings to ordinary strings

When I created my visual studio project it defaulted to forcing me to use wide strings for all the functions which take character strings. MessageBox() for example, takes a LPCWSTR rather than a const char*. While I understand that it's great for multi-lingual and portable applications, it is completely unnecessary for my simple little app. Quite frankly, it's more of a pain to constantly type TEXT() around all my strings.

Is there a compiler option, define or project setting which I can alter to fix this in my Visual Studio project?

like image 995
screenglow Avatar asked Apr 07 '09 20:04

screenglow


People also ask

What is the use of Wchar?

The wchar_t type is an implementation-defined wide character type. In the Microsoft compiler, it represents a 16-bit wide character used to store Unicode encoded as UTF-16LE, the native character type on Windows operating systems.

What is TCHAR*?

For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type. MAPI clients can use the TCHAR data type to represent a string of either the WCHAR or char type. Be sure to define the symbolic constant UNICODE and limit the platform when it is required.

What is a Wstring C++?

This function is used to convert the numerical value to the wide string i.e. it parses a numerical value of datatypes (int, long long, float, double ) to a wide string. It returns a wide string of data type wstring representing the numerical value passed in the function.


2 Answers

Right click on your project -> Properties then go to the following tree item:

Configuration Properties -> General

For Unicode select:
Use Unicode Character Strings

For normal multi-byte select:
Use Multi-Byte Character Set

When you put TEXT() or _T() around your strings, you are making it compatible with both of the character string options. If you select Use multi-byte character set then you do not need anything around your strings. If you select Use unicode character set, you need at least L in front of your strings.

By selecting Use Unicode Character Strings you are also by default using all of the Win32 API that end in W. Example: MessageBox maps to MessageBoxW.

When you select Use multi-byte character set you are also by default using all of the Win32 API that end in A. Example: MessageBox maps to MessageBoxA.

like image 165
Brian R. Bondy Avatar answered Oct 12 '22 01:10

Brian R. Bondy


It is worth noting that you can explicitly declare wide character string literals of the form:

WCHAR *s = L"Hello Wide World.";

which requires fewer keystrokes than the macros TEXT() or _T(), but which will make a wide character string even if UNICODE is not defined.

like image 40
Matthew Xavier Avatar answered Oct 12 '22 01:10

Matthew Xavier