ATL thunk机制
来源:互联网 发布:布莱克书店知乎 编辑:程序博客网 时间:2024/05/17 08:11
起初在DECLARE_WND_CLASS宏中可以知道,窗口类的窗口过程是CWindowImplBaseT< TBase, TWinTraits >的静态成员函数StartWindowProc,
在StartWindowProc第一次被调用的时候,它把CWindowImplBaseT< TBase, TWinTraits >的非静态成员函数通过thunk机制设置为窗口过程。
template <class TBase, class TWinTraits>
LRESULT CALLBACK CWindowImplBaseT< TBase, TWinTraits >::StartWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CWindowImplBaseT< TBase, TWinTraits >* pThis = (CWindowImplBaseT< TBase, TWinTraits >*)_AtlWinModule.ExtractCreateWndData();
ATLASSERT(pThis != NULL);
if(!pThis)
{
return 0;
}
pThis->m_hWnd = hWnd;
// Initialize the thunk. This is allocated in CWindowImplBaseT::Create,
// so failure is unexpected here.
pThis->m_thunk.Init(pThis->GetWindowProc(), pThis);// 初始化thunk
WNDPROC pProc = pThis->m_thunk.GetWNDPROC(); //
WNDPROC pOldProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)pProc);
#ifdef _DEBUG
// check if somebody has subclassed us already since we discard it
if(pOldProc != StartWindowProc)
ATLTRACE(atlTraceWindowing, 0, _T("Subclassing through a hook discarded./n"));
#else
(pOldProc); // avoid unused warning
#endif
return pProc(hWnd, uMsg, wParam, lParam);
}
struct _stdcallthunk
{
DWORD m_mov; // mov dword ptr [esp+0x4], pThis (esp+0x4 is hWnd)
DWORD m_this; //
BYTE m_jmp; // jmp WndProc
DWORD m_relproc; // relative jmp
BOOL Init(DWORD_PTR proc, void* pThis) /*pThis指向CWindowImplBaseT< TBase, TWinTraits > 的对象*/
{
m_mov = 0x042444C7; //C7 44 24 0C
m_this = PtrToUlong(pThis);
m_jmp = 0xe9;
m_relproc = DWORD((INT_PTR)proc - ((INT_PTR)this+sizeof(_stdcallthunk)));
// write block from data cache and
// flush from instruction cache
FlushInstructionCache(GetCurrentProcess(), this, sizeof(_stdcallthunk));
return TRUE;
}
//some thunks will dynamically allocate the memory for the code
void* GetCodeAddress()
{
return this;
}
void* operator new(size_t)
{
return __AllocStdCallThunk();
}
void operator delete(void* pThunk)
{
__FreeStdCallThunk(pThunk);
}
};
class CDynamicStdCallThunk
{
public:
_stdcallthunk *pThunk;
...
};
typedef CDynamicStdCallThunk CStdCallThunk;
/////////////////////////////////////////////////////////////////////////////
// WindowProc thunks
class CWndProcThunk
{
public:
_AtlCreateWndData cd;
CStdCallThunk thunk;
BOOL Init(WNDPROC proc, void* pThis)
{
return thunk.Init((DWORD_PTR)proc, pThis);
}
WNDPROC GetWNDPROC()
{
return (WNDPROC)thunk.GetCodeAddress();
}
};
- ATL thunk机制
- ATL Thunk机制学习
- ATL thunk机制
- ATL中的Thunk机制学习
- ATL Thunk机制的一个例子
- ATL中的Thunk机制学习
- ATL之thunk技术
- ATL Thunk技术简单解析
- 几句话概括atl thunk技术
- thunk
- THUNK
- Thunk
- Thunk,thunk,thunk
- ATL窗口继承实现机制
- Thunk技术
- Thunk 应用
- 关于Thunk
- thunk技术!
- 路由器访问控制列表详解
- [转]inotify + rsync实现linux文件实时同步
- 为什么任务管理器变丑陋了
- mod_python 的一些用法
- 关于进程的几个问题
- ATL thunk机制
- .NET2005中在文本框中按下回车键触发提交事件
- Hibernate3 二级缓存的使用配置细节
- 开博?
- 《Dojo构建Ajax应用程序》连载一
- 完成端口与高性能服务器程序开发
- Web测试工具小结
- COM+并发性
- 好好想想