What are the steps I have to take to duplicate a LPCWSTR string?
Consider the case: LPCWSTR str = L"Copy me";
Use wcscpy()
. Here is the MSDN documentation:
http://msdn.microsoft.com/en-us/library/kk6xf663(v=vs.90).aspx
A safer variant is wcscpy_s()
. You have to allocate a buffer that is big enough to hold the copy up front:
LPCWSTR str = L"Copy me";
std::vector<wchar_t> thecopy( wcslen(str) + 1 ); // add one for null terminator
wcscpy_s(thecopy.data(), thecopy.size(), str);
// you can get a pointer to the copy this way:
LPCWSTR *strCopy = thecopy.data();
wcscpy_s()'s documentation can be found here:
http://msdn.microsoft.com/en-us/library/td1esda9(v=vs.90).aspx
Use wcscpy
LPWSTR wcscpy(LPWSTR szTarget, LPWCSTR szSource);
Target is non-constant wide-string (LPWSTR), and source is constant-wide-string.
LPCWSTR
is defined as
typedef const WCHAR* LPCWSTR;
LP - Pointer
C - Constant
WSTR - Wide character String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With