This article needs additional citations for verification. (June 2011) |
Microsoft started to consistently implement Unicode in their products quite early.[clarification needed] Windows NT was the first operating system that used "wide characters" in system calls. Using the UCS-2 encoding scheme at first, it was upgraded to UTF-16 starting with Windows 2000, allowing a representation of additional planes with surrogate pairs.
In various Windows families
Windows NT based systems
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
Name of actual A/W functions (example of lstrlen is incorrect, the 'l' indicates wide characters) |
Modern Windows versions like Windows XP and Windows Server 2003, and prior to them Windows NT (3.x, 4.0) and Windows 2000 are shipped with system libraries which support string encoding of two types: UTF-16 (often called "Unicode" in Windows documentation) and an local (sometimes multibyte) encoding called the "code page" (or incorrectly referred to as ANSI code page). 16-bit functions have names suffixed with -W (from "wide"). Code page oriented functions use the suffix -A for "ANSI". This split was necessary because many languages, including C, did not provide a clean way to pass both 8-bit and 16-bit strings to the same function. Most such 'A' functions are implemented as a wrapper that translates the code page to UTF-16 and calls the 'W' function.
Microsoft attempted to support Unicode "portably" by providing a "UNICODE" switch to the compiler, that switches unsiffixed "generic" calls from the 'A' to the 'W' interface and converts all string constants to "wide" UTF-16 versions.[1][2] This does not actually work because it does not translate UTF-8 outside of string constants, resulting in code that attempts to open files just not compiling or accidentally calling the 'A' version anyway.
Earlier, and independent of the "UNICODE" switch, Windows also provides the "MBCS" API switch.[3] This switch turns on some C functions prefixed with_mbs
, and selects the 'A' functions for the current locale.[4]
Windows CE
In Windows CE UTF-16 was used almost exclusively, with the 'A' API mostly missing.[5] A limited set of ANSI API is available in Windows CE 5.0, for use on a reduced set of locales that may be selectively built onto the runtime image.[6]
This section needs expansion. You can help by adding to it. (June 2011) |
Windows 9x
In 2001, Microsoft released a special supplement to Microsoft’s old Windows 9x systems. It includes a dynamic link library unicows.dll (only 240 KB) containing the 16-bit flavor (the ones with the letter W on the end) of all the basic functions of Windows API.
UTF-8
Microsoft Windows has a code page designated for UTF-8, code page 65001. Prior to Windows 10 insider build 17035 (November 2017)[7], it was impossible to set the locale code page to 65001, leaving this code page only available for:
- Explicit conversion functions such as MultiByteToWideChar
- A manual "chcp" command that only changes the code page for the current program's context. This is used for conhost.exe windows running Windows Subsystem for Linux.
Since insider build 17035 and the April 2018 update (nominal build 17134) for Windows 10, a "Beta: Use Unicode UTf-8 for worldwide language support" checkbox is available for setting the locale code page to UTF-8.[a] However, this option can break legacy applications as they internally call old "DBCS" APIs which only support a maximum of 2 bytes in a character, such as IsDBCSLeadByte.
There are proposals to add an API to portable libraries such as Boost to do the necessary conversion, by adding new functions for opening and renaming files. These functions would pass filenames through unchanged on Unix, but translate them to UTF-16 on Windows.[8]
Many applications imminently have to support UTF-8 because it is the most-used Unicode encoding scheme in various network protocols, including the Internet Protocol Suite. An application which has to pass UTF-8 to or from a 'W' Windows API should call the functions MultiByteToWideChar and WideCharToMultiByte.[9] To get predictable handling of errors and surrogate halves it is more common for software to implement their own versions of these functions.
Notes
- ^ Found under control panel, "Region" entry, "Administative" tab, "Change system locale" button.
References
- ^ "Unicode in the Windows API". Retrieved 7 May 2018.
- ^ "Conventions for Function Prototypes (Windows)". MSDN. Retrieved 7 May 2018.
- ^ "Support for Multibyte Character Sets (MBCSs)".
- ^ "Double-byte Character Sets". MSDN. Retrieved 7 May 2018.
our applications use DBCS Windows code pages with the "A" versions of Windows functions.
- ^ "Differences Between the Windows CE and Windows NT Implementations of TAPI". MSDN. Retrieved 7 May 2018.
Windows CE is Unicode-based. You might have to recompile source code that was written for a Windows NT-based application.
- ^ "Code Pages (Windows CE 5.0)". Microsoft Docs. Retrieved 7 May 2018.
- ^ "Windows10 Insider Preview Build 17035 Supports UTF-8 as ANSI". Hacker News. Retrieved 7 May 2018.
- ^ "Boost.Nowide".
- ^ "UTF-8 in Windows". Stack Overflow. Retrieved July 1, 2011.