I assume that LPWCSTR
is a typo for LPCWSTR
; Microsoft's weird name for a C-style string pointer. It means "long pointer to a constant wide string" and is a confusing way to write const wchar_t*
.
Is it safe to create and use a string this way?
Like any pointer, it is safe to use if it points to a valid array. In this case, it points to a string literal, which is an array with a lifespan while the program is. Therefore it is safe.
If it were pointing to an array that could be destroyed while the pointer is still in use, then it would be unsafe.
Is the allocated memory for storing the string freed when the string goes out of scope?
Not; a pointer will not manage memory for you. If you need to do this, use std::wstring
.
source share