Create a Windows program for Unicode in vc6

Source: Internet
Author: User

Follow these steps to develop Unicode programs that can run in different language systems in V6:

1. Project-settings-C/C ++ tab-Preprocessor definitions: Add _ Unicode and Unicode to it. The difference between _ Unicode and Unicode is that _ Unicode is used for Windows header files and Unicode is used for C Runtime header files.

2. replace all the char in the Code with tchar, and all char * With lptstr. All Win32 string APIs replace the previous STR with _ TCS. For example, change strcpy to _ tcscpy, but some changes are not like this.In addition, all the string constants are placed in _ T () (or _ text.

3. Project-settings-Link-category: Output-entry-point Symbol: if it is an EXE execution file, add the entry: wwinmaincrtstartup program. If it is a DLL, add dllmaincrtstartup or add nothing.

Application TypeEntry PointC running library startup Function
Ansi gui ProgramWinmainWinmaincrtstartup
Unicode GUI ProgramWwinmainWwinmaincrtstartup
ANSI Cui ProgramMainMaincrtstartup
Unicode Cui ProgramWmainWmaincrtstartup
Cui refers to the console Program

4. When the system prompts that files such as mfc42ud. dll are missing during compilation, you can find these files in the installation file and copy them to the installation directory/vc98/mfc/lib of VC.

After completing the preceding four steps, you can develop a unicode program. To generate an ASCII program, you only need to remove the _ Unicode and Unicode in step 1. The compiler will compile the corresponding program file based on whether or not this definition is provided.

Certificate -----------------------------------------------------------------------------------------------------------------------------------

Use ANSI/Unicode Universal Data Types

Microsoft provides some common data types compatible with ANSI and Unicode. 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 haveUnicode encodingConsciousness.

4. Modifying string operations

Some string operation functions need to obtain the number of characters (sizeof (szbuffer)/sizeof (tchar) of the string, while other functions may need to obtain the number of bytes of 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 the WCS, such as wcscpy, wcscpy (), and 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.

 

From:

Http://hi.baidu.com/michaelwdp/blog/item/2f3594ef9aaa5e30adafd526.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.