WSTR stands for wide string or otherwise known as a Unicode string. But note that generally you'll see LPWSTR
as strings are pointers in C++. How you get one depends upon several things. If your code is compiling for ANSI then you'll likely only get this if you call wide string functions. If you need to convert from an ANSI string to a Unicode one you have to use one of the Win32 conversion functions. If you're compiling for Unicode you're already going to be using the LPWSTR
types.
If you have a string literal then you can tell the compiler it is a Unicode string using the L
prefix.
//ANSI
"Hello"
//Unicode
L"Hello"
//ANSI or Unicode, depends on compilation
T("Hello")
If you need to compile for either ANSI or Unicode then you need to use LPTSTR
instead so the compiler choses the correct type.
LP
stands for long pointer which is just a pointer in modern processors. Since strings in C++ are character arrays and hence pointers you will either use the standard STL string
type (or equivalent) or you'll stick with C-style strings and you'll be using LPSTR
, LPTSTR
or perhaps LPWSTR
for your types. They are mean pointer to a string (Ansi, Either, Unicode).
The C
in the middle means a constant pointer meaning the string cannot be changed. Many functions require an LPCSTR
, LPCTSTR
or LPCWSTR
which means a pointer to a constant (Ansi, either, Unicode) string. The callee won't be able to modify the string. Typically you can just pass a string literal here (which is constant).
//void Foo ( LPCWSTR name )
Foo(L"Bob");