Several conversion methods to Unicode strings under VC

Source: Internet
Author: User

In the environment of vc6.0, the characters are usually encoded in ANSI mode.ProgramOr the interaction between applications requires UNICODE character encoding. For example, you can use GDI + or sqlite3 links. In VC, which methods can be used to convert characters to Unicode conveniently.

 

1. Use the uses_conversion method in ATL and then use the a2w or T2W Method for conversion. This conversion method is mainly applied for memory in the stack, so it is not a safe method, it is prone to overflow.

 

2. directly use the multibytetowidechar method to convert a string to a Unicode character. before conversion, there is a method that is set to null at the position of the string pointer to be converted for the first time. At this time, the returned value is the length of the string to be converted, and then the memory is applied for conversion. This method requires a lot of manual writing.CodeAnd manually released.

 

3. The application uses the combstr class in ATL. First, it applies for an empty class object and then uses the append method to embed its own string into the string class. At this time, after using (BSTR) for forced conversion, you can obtain the Unicode string. This method avoids manual memory application and memory release. Relatively convenient. Of course, the _ bstr_t class is similar.

 

4. If the cstring method is used and the code is compiled in non-ANSI mode, you can use the sysallocstring method of cstring to obtain the Unicode string in cstring. However, this method requires manual release of memory units, call sysfreestring.

 

 

 

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.