-
-
[求助]HOOK(WH_CALLWNDPROC)导致crash?
-
发表于:
2008-12-20 15:14
8339
-
[求助]HOOK(WH_CALLWNDPROC)导致crash?
1.问题描述:
程序A用来设一个HOOK,把DLL map 到另一个程序calc.exe,用WH_CALLWNDPROC的回调处理。HOOK设置没有问题,但一点calc.exe里的菜单的"关于"时,就crash掉了,如图:
----------------------------------------------------------------------------------------------------
2. DLL里部分代码
#pragma data_seg (".shared")
HWND g_hWndOth = 0;
HHOOK g_hHook2 = 0;
#pragma data_seg ()
#pragma comment(linker,"/SECTION:.shared,RWS")
int EnHook(HWND hWndOth)
{
g_hWndOth = hWndOth;
//设置HOOK
g_hHook2 = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc2, hDll, GetWindowThreadProcessId(hWndOth,NULL) );
if(g_hHook2==NULL)
{
return 0;
}
return 0;
}
LRESULT HookProc2 ( int code,
WPARAM wParam,
LPARAM lParam )
{
//里面就算不放处理语句,还是会出现crash问题
return ::CallNextHookEx(g_hHook2, code, wParam, lParam);
}
----------------------------------------------------------------------------------------------------
3. Try程序来设置HOOK
void CTryDlg::OnOK()
{
HWND hWndOth = ::FindWindow("SciCalc","计算器");
if(!hWndOth)
{
MessageBox("Can't find the file!","Info",0);
return;
}
//Set Hook
EnHook(hWndOth);
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!