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.

Comments (22)
  1. DWalker07 says:

    15 years of this blog! I have learned a lot of stuff by reading here. Thank you, Raymond.

  2. Ray Koopa says:

    15 years! Chance in a second edition of your book? Already loved the collection in the first one. It’s not signed yet though :(

  3. laonianren says:

    Congratulations again! Though it doesn’t seem like five years since the tenth anniversary.

  4. Richard says:

    I was 12 when you started this blog. Just found it this month and it’s been a great read and I’ve learned a lot. Thank you.

  5. Rich says:

    The blog I have most looked forward to reading every day for 15 years. Thanks Raymond !

  6. James Curran says:

    Well, I guess it appropriate you discussed thunks — something I hadn’t thought about in 15 years…

  7. Paul Topping says:

    Always a great and interesting blog! Thanks!

  8. Ben says:

    Perfect topic for an anniversary!

  9. Henry says:

    Thank you, Raymond. It wouldn’t have made sense without you. You bring order into chaos.

  10. BC says:

    Your blog is the most useful to me, the info and insight you provide have explained many issues, our customers are getting better quality product, thanks to you!

  11. Gee Law says:

    I believe that when GetWindowLongPtr returns a cookie instead of the actual procedure address is an implementation detail, is it? (I’m suggesting you emphasize this so that less people coming across this blog entry base the correctness of their application on it.)

  12. Joe McLaughlin says:


    I’ve been reading (and recommending) your blog for a long time. Congrats on 15 years, and keep up the good work.

  13. Pascal says:

    I have followed you during my entire programming career. 15 years already… Just wanted to say thank you.

  14. Rutger Ellen says:

    Wow 15 years, that’s as long as the noord/zuid lijn took to build. You already payed soms attention to it with your article about the river Amstel

  15. Mark S says:

    I’ve read every one of your posts. And the book. Time sure flies!

    I miss the tales of dodgy things with compatibility, I would always trot them out when people complained about Windows, e.g. (“Yee-haw cowboy!”), (“Manufacturers will do anything to save a nickel.”)

    1. Mark S says:

      I looked through the archives and saw the Danish stuff; funny enough, I was in Norway and Denmark this past winter, and now I know what you mean; I was introduced to the “Kamelåså” video (, which you actually linked to in the mid-2018 clearance, and was presumably referenced in the last comment here: (I didn’t realize how old it was!); I also could not comprehend or pronounce that so-called “d” when I was there.

      I explained the bizarre numbering system to a friend and showed him the video, and we happened to see some Scandinavian-looking folk a few days later while hiking, and loudly mumbled “ah, kamelåså” to each other; we were taken by surprise when they came up to us and said, “so how did you learn Danish?” (they were Norwegian)

  16. cheong00 says:

    Say, how about writing something about whether something is cooking on GUI support of WSL? I think the WSL folks would eventally want to find way to allow GUI applications for *nix to run under Windows.

    In X, the program is disconnected from the windows it created (you can have your program run on a server with display sent to X server on another machine) How would that be under Windows? I suppose the shell should be able to connect the window and its underlying process so it can perform task switching or closing window correctly. I’m very curious on how Microsoft would implement that.

    If that’s happening, please share when you can talk about that.

    1. Rick C says:

      The event-driven nature of X is pretty different from Windows. I’m not sure if you could make it work without running an X server.

      As it happens, if you run an X server (like Ximg), you can run X gui programs with WSL. I’ve tried several things, like xeyes, xemacs, xscreensaver, and a browser (IIRC, Firefox) and they all worked.

      1. cheong00 says:

        “How Windows is supposed to handle the difference between the models”is the kind of things I’m curious.

  17. Wowee, thank you Raymond for your incredible 15 years of writing on this blog! Here’s to the next 15 years! 🍻

  18. Nico says:

    Wow, 15 years, and I’ve been reading it for about 12 years. Holy cow, you should write a book! :)

    Very impressive, Raymond, and thank you for all the great history, insight, and humor.

    Now… any chance for Suggestion Box V?

  19. Marcel says:

    Wow, that means I have been reading this blog for 14 years or so and as I’ve started at the beginning I read every one of your 5400 posts. Thank you, this is incredible. Cheers to the next 15 years ;-)

Comments are closed.

Skip to main content