What exactly is a PWSTR and why use this naming compared to char*, std::string, or CString in C++?
a PWSTR would be a wchar_t
string pointer. That is a UNICODE (usually UCS2) string with each character taking 16 bits.
a char*
would be a pointer 8 bits per character. this could be ASCII, ANSI, UTF8, or one of many hundreds of other encodings. Although you only need to worry about encodings if you need the string to hold languages other than English or special symbols.
In general, The Windows API is all UNICODE internally so most Windows programmers use wchar strings. But std::string
and CString
can both be UNICODE if the right symbols are #defined
, so your choice between PWSTR
, std::string
and CString
will be a matter of preference or the convention of the codebase you work with.
When whichever library you are working with wants a PWSTR
. This is a, according to naming convention used in Windows, pointer to a string of wide-characters.
By default, you should use std::string
/std::wstring
. Only when you interface with someone expecting something else should you change that.
You can get a PCWSTR
from a std::wstring
with the c_str()
method. CString
is MFC, if I recall.
PWSTR= pointer to a wide string = WCHAR* in windows
The Windows SDK is very hung up on typedefs for types and pointers to types.
"When in Rome" - use whatever string type the project you're working on requires. String types aren't important enough to stress out about or try to force your one true way upon whatever is being used.