Unicode programming in VC
In Windows, programming supports Unicode. The general trend is that the underlying system of Windows 2 k is Unicode-based. Even if you call the ansi api (end with a, such as setwidowstexta ), the system will also dynamically allocate a piece of memory on the default heap of your process, store the converted Unicode string, and then pass the converted string to the API, if you call an API whose return value is an ANSI string, Windows will perform reverse conversion in the background, which is time-consuming !! Even if you don't consider efficiency, don't you want your software to be internationalized? Do you still want to face the embarrassing problem of half a Chinese character?
In fact, Unicode programming in VC is not troublesome, probably as follows:
1. add Unicode and _ Unicode preprocessing options to the project, in vc.net, project-> property-> C/C ++-> Preprocessor adds these two macro definitions to "preprocessing definition" (Project-> Settings-> C/In vc6/ c ++-> Preprocessor definitions in general ).
2. Include <tchar. h> (Generally in stdafx. h) then replace all the variables defined using char * With lptstr/tchar * or lpctstr/const tchar * (corresponding to const char *).
3. Wrap all string constants with _ T () macros, such as tchar * sztext = _ T ("My text ");
4. All the C-database string operation functions are replaced accordingly, such
Strlen-> _ tcslen
Strcat-> _ tcscat
Strcmp-> _ tcscmp
......
Note that the "text length" in these functions are the number of characters, rather than the number of char. For details, see msdn.
5. generally, no special processing is required for API calls. After Unicode and _ Unicode are defined, all APIs are directed by macros to the version ending with W (if not defined, they are directed to the version ending with ).
In fact, what we mentioned above is not to force you to use Unicode. If you still want to use ANSI, it's okay to remove the two macros defined in the first step, continue Our ANSI programming !!