How can I get the actual window procedure address and not a thunk?

Raymond Chen

Raymond

We saw some time ago that the Get­Window­Long­Ptr function returns a magic cookie if it needs to thunk the message. The Call­Window­Proc function understands this magic cookie and calls the original window procedure after converting the message to the appropriate character set. But what if you want to get the actual window procedure and not a thunk? (For example, because you’re writing some debugging or diagnostic code, and you want to log the actual window procedure address.)

The system returns a thunk if you call Get­Window­Long­PtrA but the window procedure expects Unicode messages, or if you call Get­Window­Long­PtrW but the window procedure expects ANSI messages. So you can avoid the character set thunk by checking the character set of the top-level window procedure by calling Is­Window­Unicode. If it reports that the top-level window procedure is Unicode, then use Get­Window­Long­PtrW. Otherwise, use Get­Window­Long­PtrA.

Unrelated bonus chatter: This blog has been running for 15 years now. Sorry I didn’t celebrate with some super-fascinating topic.

Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.