Support for Unicode
Unicode is a specification for supporting all character sets, including character sets that cannot be represented in a single byte. If you are programming for an international market, consider using either Unicode or multibyte character sets (MBCS), or enabling your program so you can build it for either by changing a switch.
A "wide character" is a two-byte multilingual character code. Most characters used in modern computing worldwide, including technical symbols and special publishing characters, can be represented according to the Unicode specification as a wide character. Characters that cannot be represented in one wide character can be represented in a Unicode pair with Unicode's surrogate feature. Because each wide character is always represented in a fixed size of 16 bits, using wide characters simplifies programming with international character sets.
A wide-character string is represented as a wchar_t array and is pointed to by a wchar_t* pointer. Any ASCII character can be represented as a wide character by prefixing the letter L to the character. For example, L'\0' is the terminating wide (16-bit) NULL character. Similarly, any ASCII string literal can be represented as a wide-character string literal by prefixing the letter L to the ASCII literal (L"Hello").
Generally, wide characters take more space in memory than multibyte characters but are faster to process. In addition, only one locale can be represented at a time in multibyte encoding, whereas all character sets in the world are represented simultaneously by the Unicode representation.
The MFC framework is Unicode-enabled throughout, except for the database classes. (ODBC is not Unicode-enabled.) MFC accomplishes Unicode enabling by using "portable" macros throughout, as shown in the following table:
Portable Data Types in MFC
|Non-portable data type(s)||Replaced by this macro|
|char*, LPSTR (Win32 data type)||LPTSTR|
|const char*, LPCSTR (Win32 data type)||LPCTSTR|
Class CString uses _TCHAR as its base and provides constructors and operators for easy conversions. Most string operations for Unicode can be written by using the same logic used for handling the Windows ANSI character set, except that the basic unit of operation is a 16-bit character instead of an 8-bit byte. Unlike working with multibyte character sets (MBCS), you do not have to (and should not) treat a Unicode character as if it were two distinct bytes.
What do you want to do?
- Install Unicode support via MFC
- Enable Unicode in my program
- Enable both Unicode and MBCS in my program
- Use Unicode to create an internationalized program
- Learn the benefits of Unicode, including how using Unicode makes my program more efficient on Windows 2000
- Use wmain so I can pass wide-character arguments to my program
- See a summary of Unicode programming
- Learn about generic-text mappings for byte-width portability