Mfc tchar and CHAR convert each other

Source: Internet
Author: User

UNICODE is not defined, so the strings in it simply use "". TCHAR and char must be converted if UNICODE definitions are included during project creation.

First, convert TCHAR to char.

 

 

// Convert TCHAR to char
// * Tchar is a TCHAR pointer, and * _ char is a char pointer.
TcharToChar (const TCHAR * tchar, char * _ char)
{
Int iLength;
// Get the byte length
ILength = WideCharToMultiByte (CP_ACP, 0, tchar,-1, NULL, 0, NULL, NULL );
// Assign the tchar value to _ char
WideCharToMultiByte (CP_ACP, 0, tchar,-1, _ char, iLength, NULL, NULL );
}
 

Then convert char to TCHAR.

[Cpp] view plaincopyprint?
// Same as above
CharToTchar (const char * _ char, TCHAR * tchar)
{
Int iLength;
 
ILength = MultiByteToWideChar (CP_ACP, 0, _ char, strlen (_ char) + 1, NULL, 0 );
MultiByteToWideChar (CP_ACP, 0, _ char, strlen (_ char) + 1, tchar, iLength );
}

 

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.