Question

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?

Était-ce utile?

La solution

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.

Autres conseils

CHAR szString[] is synonymous with CHAR * szString. Both are pointers to strings. A pointer to a zero-terminated string is CHAR*, and a pointer to a zero-terminated wide string would be WCHAR* (not WCHAR**).

Now, if you want to get pedantic, you could (wrongly) claim that CHAR[] is "just an array of characters", in which case "rgc" might be the correct prefix.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top