Best method for storing this pointer for use in WndProc

前端 未结 10 828
南旧
南旧 2020-11-29 20:06

I\'m interested to know the best / common way of storing a this pointer for use in the WndProc. I know of several approaches, but each as I underst

10条回答
  •  感情败类
    2020-11-29 20:43

    While using the SetWindowLongPtr and GetWindowLongPtr to access the GWL_USERDATA might sound like a good idea, I would strongly recommend not using this approach.

    This is the exactly the approached used by the Zeus editor and in recent years it has caused nothing but pain.

    I think what happens is third party windows messages are sent to Zeus that also have their GWL_USERDATA value set. One application in particular was a Microsoft tool that provied an alternative way to enter Asian characters in any windows application (i.e. some sort of software keyboard utility).

    The problem is Zeus always assumes the GWL_USERDATA data was set by it and tries to use the data as a this pointer, which then results in a crash.

    If I was to do it all again with, what I know now, I would go for a cached hash lookup approach where the window handle is used as the key.

提交回复
热议问题