VC ++ 6.0 supports Unicode programming, but the default value is ANSI. Therefore, developers only need to change the programming Code You can easily write Unicode-Supported Applications. Program .
-
- After installation: Copy mfc42u *. * under vc98/mfc/lib to the corresponding installation directory.
-
- Add Unicode and _ Unicode preprocessing options to the project: open [project]-> [set…] In the "pre-processing program definition" in the C/C ++ label dialog box, remove _ MBCS and add _ Unicode and Unicode. (Note that separate them with commas ). before Unicode and _ Unicode are defined, all functions and types Use the ANSI version by default. After Unicode and _ Unicode are defined, all the MFC classes and Windows APIs have been changed to the wide-byte version.
-
- Set the program entry point: Because the MFC application has a special program entry point for Unicode, we need to set the entry point. Otherwise, a connection error occurs. To set an entry point, open [project]-> [set…]. Dialog box, fill in wwinmaincrtstartup in the entry point of the output category on the Link Page.
- Use ANSI/Unicode universal data types: Microsoft provides some ANSI and Unicode compatible universal data types. Our most common data types include _ T, tchar, lptstr, and lpctstr. By the way, lpctstr and const tchar * are exactly the same. Here, l indicates the long pointer, which is left behind for compatibility with Windows 3.1 and other 16-bit operating systems. In Win32 and other 32-bit operating systems, the long pointer, near pointer, and far modifier are both intended for compatibility and have no practical significance. P (pointer) indicates a pointer; C (const) indicates a constant; t (_ t macro) indicates compatibility with ANSI and Unicode, STR (string) this variable is a string. In summary, we can see that lpctstr indicates a string that points to a fixed address and can change the semantics according to some macro definitions. For example, tchar * sztext = _ T ("Hello !"); Tchar sztext [] = _ T ("I Love You"); lpctstr lpsztext = _ T ("Hello everyone !"); It is best to change the parameters in the function, for example, MessageBox (_ T ("hello"); in fact, in the preceding statement, even if you do not add a _ t macro, the MessageBox function will automatically forcibly convert the "hello" string. However, we recommend that you use the _ t macro to indicate that you are aware of Unicode encoding.
-
- Modifying string operations some string operation functions need to obtain the number of characters (sizeof (szbuffer)/sizeof (tchar) of the string )), other functions may need to obtain the number of bytes in the string sizeof (szbuffer ). You should pay attention to this problem and carefully analyze the string operation functions to confirm the correct results. ANSI operation functions start with STR, such as strcpy (), strcat (), strlen (); Unicode operation functions start with WCS, such as wcscpy, wcscpy (), wcslen (); ANSI/Unicode operation functions start with _ TCS _ tcscpy (C Runtime Library); ANSI/Unicode operation functions start with lstr lstrcpy (Windows function); Considering compatibility between ANSI and Unicode, we need to use a universal string operation function starting with _ TCS or starting with lstr.