Last time we discussed a common Windows SDK type: PCWSTR. You can follow the same approach of the previous post to decode another common Win32 type: PWSTR.
PWSTR is very similar to PCWSTR: the only difference is the missing “C” after the initial “P”.
So, splitting PWSTR up into pieces like we did last time, you get:
- The initial P, which stands for pointer. So, this is a pointer to something.
- [There is no C in this case, so the “thing” pointed to is not const]
- The remaining WSTR part, which stands for WCHAR STRing, and represents the target of the pointer.
So, a PWSTR is a pointer (P) to a (non-const) Unicode UTF-16 NUL-terminated C-style string (WSTR). In other words, PWSTR is the non-const version of the previous PCWSTR.
Considering its const type qualifier, PCWSTR is used to represent read-only input string parameters; on the other hand, the non-const version PWSTR can be used for output or input-output string parameters.
As already seen for PCWSTR, there is the perfectly equivalent variant with the initial “LP” prefix instead of “P”: LPWSTR.
The PWSTR and LPWSTR definitions from <WinNT.h> are like that:
typedef _Null_terminated_ WCHAR *LPWSTR, *PWSTR;
Note the _Null_terminated_ annotation, used to specify that the WCHAR array must be null-terminated.
3 thoughts on “Decoding Windows SDK Types: PWSTR”