I am trying to find a substitute for LPWSTR for porting a project to gcc.
typedef __nullterminated WCHAR *NWPSTR, *LPWSTR, *PWSTR;
What is null terminated ? so would it be safe if I did something like this:
typedef WCHAR *LPWSTR
I am trying to find a substitute for LPWSTR for porting a project to gcc.
typedef __nullterminated WCHAR *NWPSTR, *LPWSTR, *PWSTR;
What is null terminated ? so would it be safe if I did something like this:
typedef WCHAR *LPWSTR
Copyright © 2021 Jogjafile Inc.
The
__nullterminatedpart is a SAL annotation. SAL is a Microsoft specific technology to annotate function parameters, return values, function behaviors, etc. to help finding bugs and reduce C/C++ code defects using the Visual Studio Code Analysis tool. You can read about SAL here on MSDN:WCHARis defined in the Windows Platform SDK headers basically as a typedef forwchar_t, which is a 16-bit character type in the Microsoft Visual C++ compiler. This is used as a "character unit" for the Unicode UTF-16 encoding, which is the default de facto Unicode encoding of Windows APIs.Note that other compilers like GNU GCC on Linux consider
wchar_tto be a 32-bit character unit (not 16-bit), so you have to pay attention here for the portability of your code.(Note: Modern versions of Windows support Unicode UTF-16 with the so called surrogate pairs, so you can have a couple of adjacent
WCHARs defining a surrogate pair.)NWPSTR,LPWSTRandPWSTRare all synonyms, defined as pointers toWCHAR, i.e. considering also the__nullterminatedSAL annotation, they are pointers to "raw" C-style NUL-terminated Unicode UTF-16 strings.Basically, this is the Windows Win32 Unicode equivalent of the classical C's
char*.I've been programming Windows in C++ for several years, and I've never met this
NWPSTRto be honest :)The name
PWSTRis built using the following elements:P: pointerW: "wide", i.e.WCHAR/wchar_t-based, i.e. Unicode UTF-16STR: stringSo,
PWSTRmeans a pointer to aWCHAR/wchar_tstring, i.e. a Unicode UTF-16 string, as already stated above.LPWSTRis just an old name for the same thing; the initialLmeans "long", and that dates back to a time when there were "long pointers" which could access memory farther than "short" or "near" pointers :) Those days are no more.And, if you put a
Cin those names, you have typedefs for the read-onlyconstcounterparts, e.g.:PCWSTRorLPCWSTRare basicallyconst wchar_t*NUL-terminated Unicode UTF-16 strings.You will find
PCWSTRand the older equivalentLPCWSTRused a lot in Windows header files and Windows API documentation to represent Unicode UTF-16 "input" (i.e.const) C-style NUL-terminated strings.