vc++:char* or string converted to LPCWSTR

Source: Internet
Author: User
Tags visual studio 2010

Visual Studio 2010 is Unicode by default, and projects that are compiled successfully in VC 6.0 often have type errors in VS2010. The common error is that you cannot convert from const char * to LPCWSTR, such as using CreateDC ("display", null,null,null), if you use CAST (LPCWSTR) "Display", though you can pass, But the encoding will go wrong.  The possible way is to use text ("display") to convert, CreateDC (text ("Display"), null,null,null); Another way is: the Project menu-project Properties (last)-Configuration properties-General-Project Default--character set, will use the Unicode character set instead of set.

Lpcwstr
MSDN Original:

An LPCWSTR was a 32-bit pointer to a constant string of 16-bit Unicode charactor, which could be null-terminated. This type is declared as Follows:typedef const wchar_t* LPCWSTR;

LPCWSTR is a 32-bit pointer to a Unicode-encoded string that is the WCHAR type, not the char type.
Because the encoding is Unicode by default after VS2005, some functions call the Unicode method (function name +w,exp:messagebox+w=messageboxw) instead of Asni mode (the function name +a,exp:) when used. MESSAGEBOX+A=MESSAGEBOXA).

If you encounter a parameter error (cannot convert parameter * from ' const char [* *] ' to ' LPCWSTR '), consider looking at the declaration, if there is a asni way, just add a A to the back of the function, or change char * to WCHAR * when defining parameters.

Reference Link: Http://baike.baidu.com/view/7716877.htm?fr=aladdin

vc++:char* or string converted to LPCWSTR

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.