How to convert a CString to a LPCWSTR

I have a Cstring and I need to convert it to a LPCWSTR.  How can this be done?

PT
ptrennumAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Ah, you mean the other way round? Then, that is

wchar_t* pwsz = L"Test";
char* psz = new char[wcslen(pwsz) + 1];

wcstombs(psz, pwst, wcslen(pwsz) + 1);
0
 
ptrennumAuthor Commented:
I actually need to convert it to a wchar_t - Sorry about that, the conversion for the CString would be:

(LPCWSTR)(cstring)
0
 
ptrennumAuthor Commented:
ok increased points on this one asI'm loooking for a relatively quick response
PT
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Jaime OlivaresSoftware ArchitectCommented:
0
 
Jaime OlivaresSoftware ArchitectCommented:
0
 
jkrCommented:
I'd use

CString strTest = "Test";
wchar_t* pwsz = new wchar_t[strTest.GetLength() + 1];

mbstowcs(awc, (LPCTSTR) strTest, strTest.GetLength() + 1);
0
 
ptrennumAuthor Commented:
The problem I'm having is with the privilege code from yesterday.  the pwszAccount is asking to be converted from a wchar_t* to a LPTSTR and when I do the conversion i only get the first character back from the original string.

PT
0
 
ptrennumAuthor Commented:
You're the man!

Thanks again

PT
0
 
jkrCommented:
Thanx :o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.