Conversion of CString to LPCWSTR
-
Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar
-
Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar
Use the function mbstowcs. It takes a char pointer, so use GetBuffer function of CString to get char pointer. Alternatively you can use AllocSysString method to BSTR, which can be easily passed as LPCWSTR. Arsalan Malik
-
Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar
use the member function GetBuffer() Link to microsoft documentation of CString::GetBuffer example:
CString MyString("This is my string"); LPCWSTR MyLPCWSTR = (LPCWSTR) MyString.GetBuffer(MyString.GetLength());
note: the return type of GetBuffer() is LPTSTR
-
use the member function GetBuffer() Link to microsoft documentation of CString::GetBuffer example:
CString MyString("This is my string"); LPCWSTR MyLPCWSTR = (LPCWSTR) MyString.GetBuffer(MyString.GetLength());
note: the return type of GetBuffer() is LPTSTR
Thanks for the info.. It was working perfectly.. Thanks Sudhakar
-
Thanks for the info.. It was working perfectly.. Thanks Sudhakar
Remember that for every call to
GetBuffer()
, there must also be a call toReleaseBuffer()
. If you are not going to be editing the internalCString
buffer, why ask for a writeable copy? Try this instead:CString MyString("This is my string");
LPCWSTR MyLPCWSTR = (LPCWSTR) ((LPCTSTR) MyString);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen