Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sz and pwsz prefixes in WinAPI

I'm a little confused now with the hungarian notation prefixes in WinAPI for CHAR strings and WCHAR strings. When we use a CHAR string usually such a prefix is used:

CHAR szString[] = "Hello";

We have a zero-terminated string szString so everything's fine. But when we use a WCHAR string usually such a prefix is used:

WCHAR pwszString[] = L"Hello";

It stands for pointer to zero-terminated wide string... but our type doesn't look like this. Pointer to zero-terminated wide string is WCHAR** or PWSTR*. Am I wrong? Why it's sz for CHAR strings and pwsz but not wsz for WCHAR strings?

like image 564
spandei Avatar asked Apr 15 '13 14:04

spandei


1 Answers

The second example is misleading (though not uncommon). It should be either one of these two:

WCHAR wszString[] = L"Hello";
WCHAR *pwszString = L"Hello";

Since an array can be used in most contexts that a pointer is expected, some programmers get a little sloppy about the distinction.

Hungarian is out of style, but it can be useful when used well.

like image 125
Adrian McCarthy Avatar answered Nov 15 '22 08:11

Adrian McCarthy