Chapter 2 Unicode
The Unicode Windows header file in Windows defines several data types about Unicode: Wchar Unicode Characters PWSTR points to the Unicode string PCWSTR pointing to a constant Unicode string, the pointer of the Unicode string, while the Windows header is also set up ANSI / Unicode's universal Data types, PTSTR, and PCTSTR, such data points to that character, depending on whether the Unicode macro is defined when the compiler module is compiled. Here this macro Unicode does not undertine prefix, with a prefixed macro _Unicode is used for C operation period. When compiling the source code module, these two macros must usually define. There are two versions in Windows, one is to accept Unicode strings, for CreatWindowSexw; a receiving ansi string, for CreatWindowSexa. In the code, we usually only include calls to CreatWindowSex instead of calling these, because CreatWindowSex is actually defined as a macro in the WinUser.h file. Therefore, when compiling the source code module, which CreatWindowSex version is called, depending on whether you have a unicode definition. To create a DLL for other developers, it is best to provide two output functions, an ANSI version, a Unicode version, in the ANSI version, just allocate memory, execute the necessary string conversion, then call the function Unicode version. Some older functions in Windows have a big problem, they do not accept Unicode strings. This should avoid using these functions. All new and unmatched functions have two versions of ANSI and Unicode in Windows2000.
The Windows string function Windows provides a wide range of range of string operation functions, which are components of the operating system, often used by large applications. Since these functions are used, they may be loaded into RAM when running, so they call them rather than using C run libraries, will help to slightly improve your running performance. To use the function of the operation string in the classic operating system function, you must add the shlwapi.h header file. These string functions, existing ANSI, also have Unicode versions, so when you create an application, if you define Unicode, they will automatically expand into a wide character version.
Become an application that complies with ANSI and Unicode to make your app in accordance with Unicode, you should follow some of the basic principles: 1. Stroke the text as a character array instead of a Chars array or byte array. 2. Use the general data type (such as TCHAR and PTSTR) for text characters and strings. 3. Use the explicit data type (such as byte and pbyte) for bytes, byte pointers, and data caches. 4. Use the Text macro for primary characters and strings. 5. Perform a global replacement (for example, replace PSTR with PTSTR). 6. Modify the string operation problem. For example, functions typically want you to pass a cache size in characters, not bytes. This means that you should not pass SIZEOF (SizBuffer / SizeOf (Tchar). In addition, if you need to assign a memory block for the string, you have the number of characters in the string, then please Remember to assign memory by bytes. This is to call Malloc (ncharacters * sizeof (tchar)) instead of calling malloc (ncharacters). In all principles mentioned above, this is the most difficult remember One principle, if the operation is wrong, the compiler will not issue any warnings. WindWos provides a function that operates with the Unicode string as follows: lstrcat places a string at the end of another string LSTRCMP to two strings Perform case-sensitive comparison LSTRCMPI for two strings to distinguish case sensitive LSTRCPY copy a string to another location of LSTRLEN to return to the length of the LSTRLEN Returns the length of these functions as a macro, ie Speaking of them can be automatically extended as Unicode / ANSI, will automatically extend according to whether UNICODE is defined. Windows provides two functions to convert unicode strings: PTSTR Charlower (PTSTR pszstring); PTStr Charupper (PTSTR pszstring) ); Either convert a single character or convert the entire string end of 0. To convert the entire string, you only need to pass the address of the string. To convert a single character, you must pass each character like this. : Tchar clowercasecha = charlower (ptstr) szstring [0]; converts a single character into a PTSTR to call the function, pass a value to it, in which the lower 16 bits contain this character, more High 16-bit contains 0. When the function sees that the higher is 0, the function knows that you want to convert a single character, not the entire string. The return value is a 32-bit value, the lower 16 bits are The character that has been converted. When the resource compiler compiles all your resources, the output file is the binary file of the resource. The string value in the resource (string table, dialog template, menu, etc.) is always written in Unicode string. Windows with istext The Unicode function is distinguished by the open text is an ANSI character also Unicode character. DWORD ISTEXTUNICODE (const pvoid pvbuffer, int CB, PRESULT); the problem with text files is that their content is not stringent and clear rule, so it is difficult to determine whether the file contains an ANSI character or Unicode characters.