GetWindowLong
code> only means that these variants exist, but the reason is not mentioned.
I can imagine that it must match the encoding of CreateWindowEx (also in A/W style) or RegisterClass, but for many reasons, I Think it doesn’t make sense. Obviously, this is important because someone reported that the Unicode version may fail on XP (even if XP is NT, as far as I know, all Unicode is under the hood). I also tried to disassemble 32-bit Version of USER32.DLL (which contains two versions of GetWindowLong), and additional work has been done according to some obvious coding differences*.
Which function should I choose?
* The style of GetWindowLong is the same except for the boolean values they pass to other functions. This boolean value is compared with the flag bits in the memory structure. I can’t bother to use static code analysis for tracking.
p>
If the current window procedure is incompatible with the caller of GetWindowLongPtr, then the real function pointer cannot be returned since you can’t call it. Instead, a “magic cookie” is returned. The sole purpose of this cookie is to be recognized by CallWindowProc so it can translate the message parameters into the format that the window procedure expects.
For example, suppose that you are running Windows XP and the window is a UNICODE window, but a component compiled as ANSI calls GetWindowLong(hwnd, GWL_WNDPROC). The raw window procedure can’t be returned, because the caller is using ANSI window messages, but the window procedure expects UNICODE window messages. So instead, a magic cookie is return ed. When you pass this magic cookie to CallWindowProc, it recognizes it as a “Oh, I need to convert the message from ANSI to UNICODE and then give the UNICODE message to that window procedure over there.”
I found out today that GetWindowLong (and GetWindowLongPtr) has’ANSI’ (A) and’Unicode’ (W) styles, even if they do not have TSTR parameters. MSDN page on GetWindowLong< /code> only means that these variants exist, but the reason is not mentioned.
I can imagine that it must match the encoding of CreateWindowEx (also in A/W style) or RegisterClass, but for many reasons, I don't think it makes sense. Obviously, this is important because someone reported that the Unicode version may fail on XP (even if XP is NT, as far as I know, all Unicode is under the hood). I also tried to disassemble 32 Bit version of USER32.DLL (which contains two versions of GetWindowLong), and additional work has been done according to some obvious coding differences*.
Which function should I choose?
* The style of GetWindowLong is the same except for the boolean values they pass to other functions. This boolean value is compared with the flag bits in the memory structure. I can't bother to use static code analysis for tracking.
p>
I believe the reason is explained in Raymond Chen’s article What are these strange values returned from GWLP_WNDPROC?
If the current window procedure is incompatible with the caller of GetWindowLongPtr, then the real function pointer cannot be returned since you can't call it. Instead, a “magic cookie” is returned. The sole of this cookie is to be recognized by CallWindowProc so it can translate the message parameters into the format that the window procedure expects.
For example, suppose that you are running Windows XP and the window is a UNICODE window, but a component compiled as ANSI calls GetWindowLong(hwnd, GWL_WNDPROC). The raw window procedure can't be returned, because the caller is using ANSI window messages, but the window procedure expects UNICODE window messages. So instead, a magic cookie is returned. When you pass this magic cookie to CallWindowProc, it recognizes it as a “Oh, I need to convert the message from ANSI to UNICODE and then give the UNICODE message to that window procedure over there.”