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 + +