One-day Windows API training (80) multibytetowidechar Function

Source: Internet
Author: User
One-day Windows API training (80) multibytetowidechar Function
During the use of software, garbled code is often encountered. Why? In many cases, character sets are different, that is, the same number represents different meanings. In Windows, ANSI and Unicode are used. If the ANSI string is displayed in Unicode mode, garbled characters are displayed. Similarly, Unicode strings cannot be displayed in ANSI functions, but must be converted to each other to display the correct strings. In operating systems after nt, all the underlying functions of windows have been changed to Unicode. If ANSI is used, it is slower than Unicode functions, the system underlying layer is converted from ANSI to Unicode and then displayed. You can use the multibytetowidechar function to convert a string from ANSI to Unicode.
 
The multibytetowidechar function declaration is as follows:
 
Winbaseapi
Int
Winapi
Multibytetowidechar (
_ In uint codePage,
_ In DWORD dwflags,
_ In lpcstr lpmultibytestr,
_ In int cbmultibyte,
_ Out_ecount_opt (cchwidechar) lpwstr lpwidecharstr,
_ In int cchwidechar );
CodePage is a code table.
Dwflags is the conversion flag.
Lpmultibytestr is the input ANSI string.
Cbmultibyte is the string length of the input ANSI.
Lpwidecharstr is the output Unicode string.
Cchwidechar is the buffer size of the output Unicode string.
 
An example of calling a function is as follows:
#001 //
#002 // String Conversion.
#003 // Cai junsheng 2007/11/28 QQ: 9073204 Shenzhen
#004 void multitowide (void)
#005 {
#006 // ANSI string.
#007 STD: String stransi ("test string conversion/R/N ");
#008
#009 //
#010 const int nbufsize = 512;
#011 tchar chbuf [nbufsize];
#012 zeromemory (chbuf, nbufsize );
#013
#014 // a unicode string.
#015 if (multibytetowidechar (cp_acp, 0, stransi. c_str (), stransi. Length (),
#016 chbuf, nbufsize)> 0)
#017 {
#018 //
#019 outputdebugstring (chbuf );
#020}
#021
#022}

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.