Is it possible to use multiple “character sets” in a visual studio 2010 project?

后端 未结 1 870
后悔当初
后悔当初 2021-01-29 08:23

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 w

相关标签:
1条回答
  • 2021-01-29 08:54

    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.

    0 讨论(0)
提交回复
热议问题