Real-combat conversion of String series--string to LPCWSTR in C + +

Source: Internet
Author: User

Let's introduce how to convert from string to LPCWSTR today.

What type of LPCWSTR is it?
See how it's defined:

typedefconstwchar_t* LPCWSTR;

As the name implies:
LPCWSTR is a 32-bit pointer to a Unicode-encoded string that is the WCHAR type, not the char type.

For example, the second and third parameter of MessageBoxW is the LPCWSTR type.

`MessageBoxW(__in_opt HWND hWnd, __in_opt LPCWSTR lpText,            __in_opt LPCWSTR lpCaption, __in UINT uType)`

So here's the question, how about a string of strings, how to display it through MessageBoxW? This requires the conversion of string to LPCWSTR type!!

 string  image_path =  "C:\\av I.png "; size_t size = Image_path.length (); wchar_t *buffer  = new  wchar_t[size + 1 ]; MultiByteToWideChar (CP_ACP, 0 , Response->image_path.c_str (), size, buffer , size * sizeof (wchar_t)); buffer  [Size] = 0 ; Make sure to end with ' \0  ': MessageBox (null , buffer , null , null ); Delete buffer ; buffer  = null ; 

See, again. The MultiByteToWideChar function is used again. So keep in mind the use of this function.
http://blog.csdn.net/wangshubo1989/article/details/49210385

Real-combat conversion of String series--string to LPCWSTR in C + +

Related Article

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.