Is it possible to use multiple “character sets” in

2019-09-19 17:32发布

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?

1条回答
Summer. ? 凉城
2楼-- · 2019-09-19 17:53

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.

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

  1. Convert all your project settings to Unicode.

  2. 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).

  3. 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).

  4. MultiByteToWideString and WideStringToMultiByte are your friends.

查看更多
登录 后发表回答