是否可以使用多个“字符集"?在 Visual Studio 2010 项目中? [英] Is it possible to use multiple "character sets" in a visual studio 2010 project?

查看:43
本文介绍了是否可以使用多个“字符集"?在 Visual Studio 2010 项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,在 Visual Studio 2010(c++) 中,我们有 noset、unicode 和 MBCS 字符集,我们可以通过菜单或预处理器指令(如 #define _UNICODE)进行设置.我正在处理一个项目,它有一个使用 MBCS 字符集生成信息的文件(实际上它解析一个 html 文件!),项目中的其他文件通过 unicode 字符集工作以支持亚洲语言.我已经通过为文件添加 #define _MBCS 和为主文件添加 #define _UNICODE 来测试它,但收到了一些编译器错误.现在有办法解决这个问题吗?

As you know, in visual studio 2010(c++) we have noset, unicode and MBCS character sets, and we can set it by menus or by preprocessor directive like #define _UNICODE. I'm working on a project, it has a file that uses MBCS characterset to produce information (in fact it parse a html file!), and other files in the project work by unicode character set to support assian languages. I've test it by adding #define _MBCS for the file and #define _UNICODE for main file, but received some compiler errors. Now is there anyway to solve this problem?

推荐答案

LPCTSTR 是指向 TCHAR(字符串)的指针.它映射到 LPWSTR(宽字符字符串)或 LPCSTR(ansi 字符串),具体取决于 _UNICODEUNICODE 定义是否已设置.所有这些 TCHAR 内容都是 Windows 9x 时代的遗留物,当时早期版本的 Windows 在其 API 中没有 Unicode 支持,但开发人员希望针对 NT 和 9x 进行编译.所有这些现在都应该被完全弃用.

LPCTSTR is the pointer to TCHAR (string). It maps to either LPWSTR (wide char string) or LPCSTR (ansi string) depending if the _UNICODE or UNICODE defines were set. All of this TCHAR stuff was a holdover from the Windows 9x days when the earlier versions of Windows didn't have Unicode support in their APIs, but developers wanted to target compiling for both NT and 9x. All of this should be well deprecated by now.

我的建议 - 在使用 ANSI 和 UNICODE 字符串时,去掉所有的 TCHAR 代码并明确说明.

My advice - get rid of all your TCHAR code and be explicit when using ANSI vs. UNICODE strings.

  1. 将您的所有项目设置转换为 Unicode.

  1. Convert all your project settings to Unicode.

将所有 LPTSTR、LPCTSTR、TCHAR、变量显式转换为显式、LPWSTR、LPCWSTR 或 WCHAR.或者在显式处理 ANSI 字符串时:LPSTR (char*)、LPCSTR (const char*) 或 CHAR (char).

Explicitly convert all LPTSTR, LPCTSTR, TCHAR, variables to be explicitly, LPWSTR, LPCWSTR, or WCHAR. Or when explicitly dealing with ANSI strings: LPSTR (char*), LPCSTR (const char*), or CHAR (char).

在调用 Win32 API 时要明确.当您想要处理 ANSI 字符串(例如 CreateWindowA 与 CreateWindowW)时,请使用 API 的A"版本.

Be explicit when calling Win32 APIs. Use the "A" version of APIs when you want to process an ANSI string (e.g. CreateWindowA vs. CreateWindowW).

MultiByteToWideStringWideStringToMultiByte 是你的朋友.

这篇关于是否可以使用多个“字符集"?在 Visual Studio 2010 项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆