关于 ATL Windowing Thunking 中 esp 寄存器使用的问题
众所周知,ATL 通过 thunking 将窗口挂钩到它的 wndproc,这实际上用 this 指针替换 hwnd 并跳转到 wndproc,这样对 wndproc(hwnd, ...) 的调用实际上是 wndproc(this, .. .).
下面是 thunk 构造的汇编代码:
mov dword ptr [esp+0x4], pThis (esp+0x4 is hWnd)
我的问题是,由于这个 thunk 只执行一次,我们如何确保 [esp+0x4] 不会被 CPU 覆盖以调用另一个过程,并且下次调用wndproc(...)时,hwnd又被传入了吗?我的理解是 [esp+0x4] 是一个可重用的通用寄存器,用于存储任何过程的第一个参数。
这里出了什么问题?如何保证hwnd的修改是永久的?
谢谢。
It's well know that ATL hooks a window to it's wndproc by thunking, which actually replace hwnd with this pointer in place and and jumps to the wndproc so that a call to wndproc(hwnd, ...) is actually wndproc(this, ...) .
Below is the assembly code the thunk constructs:
mov dword ptr [esp+0x4], pThis (esp+0x4 is hWnd)
My question is, since this thunk only executes once, how can we be sure that [esp+0x4] will not be overwritten by CPU for calling another procedure, and next time wndproc(...) is called, hwnd is passed in again? My understanding is that [esp+0x4] is a reusable general-purpose register for storing a first parameter of any procedure.
What am wrong here? how the modification of hwnd is guaranteed to be perpetual?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我错了
,它实际上是在每次消息到达时运行。
这是因为 thunk itself ,而不是
CWindowImplBaseT<>::WindowProc()
,通过以下几行CWindowImplBaseT< 设置为窗口类的 wndproc ;>::StartWindowProc
在:I was wrong about the
part, it actually runs each time a message arrives.
this is because the thunk itself , not
CWindowImplBaseT<>::WindowProc()
, is set to be the wndproc of the window class by the following linesCWindowImplBaseT<>::StartWindowProc
in :