Why does GetWindowLong have ANSI and Unicode options?

Today I found out that GetWindowLong (and GetWindowLongPtr ) have ANSI (A) and Unicode (W) attributes, even if they don't have TSTR arguments. The MSDN page on GetWindowLong only indicates that these options exist, but does not mention why.

I can imagine that it should correspond to the encoding CreateWindowEx (which also has A / W flavors) or RegisterClass , but for many reasons I do not think this makes sense. Apparently, this is important because someone said that the Unicode version may fail on XP (although XP is NT and, as I understand it, all Unicode is under the hood). I also tried to parse the 32-bit version of USER32.DLL (which contains both versions of GetWindowLong ), and there is additional work done based on some apparent difference in encoding *.

Which function should I choose?


* GetWindowLong identical except for the boolean ones that they pass to other functions. This boolean value is compared with the flag bit in the memory structure. I can't worry to track it with static code analysis.

+4
source share
1 answer

I believe the reason is explained in Raymond Chen's article, What are these weird values ​​returned from GWLP_WNDPROC?

If the current window procedure is incompatible with the caller GetWindowLongPtr, then the actual function pointer cannot be returned, since you cannot call it. Instead, the magic cookie returns. The sole purpose of this cookie must be recognized by CallWindowProc, so it can translate the message parameters into the format that the window procedure expects.

For example, suppose you are using Windows XP and the window is a UNICODE window, but a component compiled as ANSI calls GetWindowLong (hwnd, GWL_WNDPROC). The raw window procedure cannot be returned because the caller uses ANSI window messages, but UNICODE window messages are expected in the window procedure. Therefore, magic cookies are returned instead. When you pass this magic cookie to CallWindowProc, it recognizes it as "Oh, I need to convert the message from ANSI to UNICODE, and then give the UNICODE message to this window procedure there."

+7
source

Source: https://habr.com/ru/post/1393390/


All Articles