Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert LPCWSTR to LPWSTR

Tags:

c++

How can I convert LPCWSTR to LPWSTR.

In one method I am getting an argument type as LPCWSTR. This parameter(LPCWSTR) has to be passed to another method of argument type LPWSTR.

like image 574
kanden Avatar asked Mar 22 '12 15:03

kanden


2 Answers

Create a new string, copy the contents into it, and then call the function that expects a modifiable string:

LPCWSTR str = L"bar";
std::wstring tempStr(str); 
foo(&tempStr[0]);
like image 191
David Heffernan Avatar answered Oct 06 '22 00:10

David Heffernan


LPCWSTR is a pointer to a const string buffer. LPWSTR is a pointer to a non-const string buffer. Just create a new array of wchar_t and copy the contents of the LPCWSTR to it and use it in the function taking a LPWSTR.

like image 40
Daniel Schlößer Avatar answered Oct 06 '22 01:10

Daniel Schlößer