Windows API at its best

With the advent of object-oriented programming frameworks for Windows like MFC or, most recently, .NET Framework, the average programmer doesn’t have to deal with low-level Windows API programming. Nevertheless, you can still do everything with C/C++ and pure Windows API, but with a little more work, of course.

I’m not willing to start a debate whether Windows API or Hungarian notation is good or bad. Personally, I prefer the descriptive, camelcased function names (CreateFile) in Windows API to the cryptic, as short as possible UNIX/Linux standard library functions (fopen), but that’s just a matter of taste.
Every long-lived software project has its legacy, and this is exceptionally true for operating systems where backward compatibility is essential. The Windows API carries a lot of old stuff, one of it is the Hungarian notation, it’s there, you can’t avoid it, but you get used to it pretty soon. But there are also the API functions from the 16-bit era, long pointer types (like LPSTR), or the infamous TCHAR type and related function macros.

The reason why all this got into my mind is that a few weeks ago I stumbled upon a question on StackOverflow which mentioned an interesting Windows API typename, PCZZTSTR. The original poster even called it scary, and to be honest, he was right to some extent. Nevertheless, with a little WinAPI knowledge and some googling around (it’s not a widely used type), one is able to “decrypt” this typename to a more digestible description:

  • P is for pointer,
  • CZ means C-style string which is zero-terminated,
  • the second Z signs that the string must be terminated with another zero ('\0' character), like it would be some kind of string of strings,
  • T means that the string consists of TCHARs, which are chars on pre Windows NT systems and wchar_ts on newer Windowses,
  • finally, STR simply stands for string, which may be redundant after all the previous characters, but it’s there for consistency with other string types in the API.

So PCZZTSTR essentially means just a simple C-style string of TCHARs, which is terminated with two ‘\0’ characters. It’s not so scary anymore, is it?

Leave a Reply

Your email address will not be published. Required fields are marked *

*