What limitations does the Windows console have regarding Unicode?

前端 未结 2 1600
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 08:01

It is possible to write Unicode characters to the Windows console using the WriteConsoleW function. On my Windows 7 machine, it looks like the console does not support chara

2条回答
  •  既然无缘
    2020-12-20 08:21

    Windows console is limited to Basic Multilingual Plane

    Your link to WriteConsole function says nothing about usable console characters:

    • lpBuffer [in] A pointer to a buffer that contains characters to be written to the console screen buffer.

    But what is that buffer? Simple Google search for writeconsole lpbuffer structure gives (indirect) link to the CHAR_INFO structure:

    Syntax (C++)

    typedef struct _CHAR_INFO {
      union {
        WCHAR UnicodeChar;
        CHAR  AsciiChar;
      } Char;
      WORD  Attributes;
    } CHAR_INFO, *PCHAR_INFO;
    

    But what is WCHAR UnicodeChar? Again, a simple Google search for windows wchar gives link to Windows Data Types:

    • WCHAR A 16-bit Unicode character. For more information, see Character Sets Used By Fonts. This type is declared in WinNT.h as follows: typedef wchar_t WCHAR;

    And finally, above Character Sets Used By Fonts link gives next ultimate consequence: Windows console is limited to Basic Multilingual Plane, i.e. 16-bit Unicode subset:

    Unicode Character Set

    … To address the problem of multiple coding schemes, the Unicode standard for data representation was developed. A 16-bit character coding scheme, Unicode can represent 65,536 (2^16) characters, which is enough to include all languages in computer commerce today, as well as punctuation marks, mathematical symbols, and room for expansion. Unicode establishes a unique code for every character to ensure that character translation is always accurate.

提交回复
热议问题