July 20th, 2018

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

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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.