如何将 Visual Studio 项目从使用宽字符串转换为普通字符串 [英] How do you convert a Visual Studio project from using wide strings to ordinary strings
问题描述
当我创建我的 Visual Studio 项目时,它默认强制我对所有需要字符串的函数使用宽字符串.例如,MessageBox() 采用 LPCWSTR 而不是 const char*.虽然我知道它非常适合多语言和便携式应用程序,但对于我的简单小应用程序来说完全没有必要.坦率地说,在我的所有字符串周围不断键入 TEXT() 更痛苦.
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.
是否有编译器选项、定义或项目设置可以更改以在我的 Visual Studio 项目中解决此问题?
Is there a compiler option, define or project setting which I can alter to fix this in my Visual Studio project?
推荐答案
右键单击您的项目 -> 属性,然后转到以下树项:
Right click on your project -> Properties then go to the following tree item:
配置属性 -> 常规
对于 Unicode 选择:
使用 Unicode 字符串
For Unicode select:
Use Unicode Character Strings
对于普通的多字节选择:
使用多字节字符集
For normal multi-byte select:
Use Multi-Byte Character Set
当您在字符串周围放置 TEXT()
或 _T()
时,您使其与两个字符串选项兼容.如果您选择使用多字节字符集
,那么您的字符串周围不需要任何内容.如果选择Use unicode character set
,则字符串前至少需要L.
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.
通过选择Use Unicode Character Strings
,您还默认使用所有以 W 结尾的 Win32 API.示例:MessageBox
映射到 MessageBoxW代码>.
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
.
当您选择 Use multi-byte character set
时,默认情况下您还将使用所有以 A 结尾的 Win32 API.示例:MessageBox
映射到 MessageBoxA
.
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
.
这篇关于如何将 Visual Studio 项目从使用宽字符串转换为普通字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!