Standardized programming: ANSI and the use of UNICODE
ANSI in the end what is and what is UNICODE? In fact, this is two different coding standards, ANSI characters used in the 8-bit, and UNICODE characters in a 16 bit. 8bit code can only express the ANSI 256 kinds of characters in the English alphabet that 26 is more than sufficient, but said that Chinese, Korean, Japanese, and so have thousands of characters on non-Western characters sure enough, it will be before the introduction of the UNICODE standard.
In software development, particularly the use of some of the C language string handling functions, ANSI and UNICODE is distinction is used, then the ANSI types of characters and UNICODE types of characters defined, how to use? ANSI and UNICODE and how to change?
1. Definition:
ANSI: char str [1024]; string handling functions available: strcpy (), strcat (), strlen (), and so on. UNICODE: wchar_t str [1024]; string handling functions available
2. Functions available:
ANSI: char, string handling functions available: strcat (), strcpy (), strlen () function to begin str.
UNICODE: wchar_t string handling functions available: wcscat (), wcscpy (), wcslen () function to begin with wcs.
3. Support system
Windows 98: only support ANSI.
Windows 2k: supports both ANSI and UNICODE support.
Windows CE: only supports UNICODE.
Note
1. COM inside only in UNICODE support.
2. Windows 2000 systems are based on the OS UNICODE, for use in windows 2000 ANSI is a price to pay, though not in any coding on the conversion, but such a transformation is hidden, is the occupation of system resources (CPU, memory).
3. In Windows 98 to use UNICODE, it needs its own code manually switch.
3. How to distinguish between:
In our software development that is often required to support ANSI and UNICODE support, it is impossible in the time requested type conversion, re-change the type of string, and the use of strings in the operational function. For this reason, standard C runtime library and provide a Windows-defined way.
In the C language provided inside _ UNICODE Acer (underlined), Windows provides UNICODE inside Acer (without underlined), as long as scheduled _ UNICODE Acer and the Acer UNICODE, the system will automatically switch to UNICODE version, otherwise, ANSI system in accordance with the form of compiler and run.
Acer and the only definition of the transformation can not be achieved automatically, he needs to support the definition of a series of characters.
1. TCHAR
If the definition is TCHAR UNICODE Acer is defined as wchar_t.
Typedef wchar_t TCHAR;
It is defined as char TCHAR
Typedef char TCHAR;
2. LPTSTR
If the definition is LPTSTR UNICODE Acer is defined as LPWSTR.
Typedef LPTSTR LPWSTR;
It is defined as char TCHAR
Typedef LPTSTR LPSTR;
Description: string constants in the use of the time need to use _ TEXT ( "MyStr") to support the system of automatic conversion.








0 Comments to “Standardized programming: ANSI and the use of UNICODE”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.