How do I resolve the LPCWSTR type's formal parameter types that are not compatible with the real participation of char types in VS?

Source: Internet
Author: User

After setting the character set in the project properties character set for multibyte character sets or Unicode raises two bugs, find the following information:

Workaround One:
The string that is usually entered manually is a const char* (that is, LPCSTR) type, so you simply change the messagebox in that sentence to MessageBoxA.
Workaround Two:
Parameters use the "_t" macro:
MessageBox (null,_t ("Open image failed!"), _t ("error"), MB_OK);
Or:
MessageBox (NULL, L "Openimage failed!", l "error", MB_OK);
/*
*************************************************************************************************************** *********************************
* When the project is a Unicode encoding, _t saves the string in parentheses in Unicode, and when the project is multibyte-encoded, _t the string in parentheses in ANSI mode
* The keyword "L", regardless of the encoding environment, is to save the string that follows it in Unicode mode.
*************************************************************************************************************** **********************************
*/
1. Replace Char with Thcar
2, String plus _t (""), such as _t ("Hello")
3, replace strcpy with _tcscpy, etc.
The ANSI operation functions start with STR, such as strcpy (), strcat (), strlen ();
The Unicode manipulation functions start with WCS, such as wcscpy,wcscpy (), wcslen ();
Ansi/unicode mutually compatible operation functions begin with _tcs _tcscpy (C run-time library);
Ansi/unicode mutually compatible operation functions begin with Lstr lstrcpy (Windows functions);
Considering ANSI and Unicode compatibility, you need to use a generic string manipulation function that begins with _tcs or LSTR.

Finally add header file #include <tchar.h>


Reference Link: Http://zhidao.baidu.com/question/327887942.html?qbl=relate_question_2&word=LPWSTR

How does the formal parameter type of the char type in VS LPCWSTR type not be compatible?

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.