문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top