写了一个钩子函数,但每次钩到其他进程后,那个进程就会报错关闭.哪里错了?钩子dll的主要代码:BOOL WINAPI SetTxtGetterHook(DWORD dwThreadId)
{
OutputDebugString("SetTxtGetterHook");
BOOL fOK = FALSE;
if(dwThreadId != 0)
{
OutputDebugString("SetTxtGetterHook dwThreadId != 0");
g_hinstDll=::AfxGetInstanceHandle();
g_hhook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,g_hinstDll,dwThreadId);
fOK = (g_hhook != NULL);
if(fOK)
{
}
else
{
fOK = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
}
return(fOK);
} LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam)
{
OutputDebugString("Receive msg");
return (CallNextHookEx(g_hhook,nCode,wParam,lParam));
} 调用程序的代码:
void DataGetter::installHook()
{
CWnd *pMsnWin = m_pMsgWnd->FindWindow(NULL,TEXT("UltraEdit-32 - [编辑1]"));
if(pMsnWin == NULL) {
AfxGetMainWnd()->MessageBox("No Window Found!");
return ;
}
//通过窗口句柄得到对应的线程的ID
BOOL isOK=SetQuoteGetterHook(GetWindowThreadProcessId(pMsnWin->GetSafeHwnd(),NULL));
if(!isOK)
{
AfxGetMainWnd()->MessageBox("Hook Err!");
return ;
}
}每次运行都回把UE给关掉,我也没做什么呀,帮忙看看.
(没分了,先给这些吧)
{
OutputDebugString("SetTxtGetterHook");
BOOL fOK = FALSE;
if(dwThreadId != 0)
{
OutputDebugString("SetTxtGetterHook dwThreadId != 0");
g_hinstDll=::AfxGetInstanceHandle();
g_hhook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,g_hinstDll,dwThreadId);
fOK = (g_hhook != NULL);
if(fOK)
{
}
else
{
fOK = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
}
return(fOK);
} LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam)
{
OutputDebugString("Receive msg");
return (CallNextHookEx(g_hhook,nCode,wParam,lParam));
} 调用程序的代码:
void DataGetter::installHook()
{
CWnd *pMsnWin = m_pMsgWnd->FindWindow(NULL,TEXT("UltraEdit-32 - [编辑1]"));
if(pMsnWin == NULL) {
AfxGetMainWnd()->MessageBox("No Window Found!");
return ;
}
//通过窗口句柄得到对应的线程的ID
BOOL isOK=SetQuoteGetterHook(GetWindowThreadProcessId(pMsnWin->GetSafeHwnd(),NULL));
if(!isOK)
{
AfxGetMainWnd()->MessageBox("Hook Err!");
return ;
}
}每次运行都回把UE给关掉,我也没做什么呀,帮忙看看.
(没分了,先给这些吧)
你试一下把OutputDebugString注释看看呢
LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam)
{
//OutputDebugString("Receive msg");
return (CallNextHookEx(g_hhook,nCode,wParam,lParam));
}
我把所有的OutputDebugString都去掉了,但还是报错Uedit32.exe 中的 0x174a12a8 处未处理的异常: 0xC0000005: 读取位置 0x174a12a8 时发生访问冲突 。只要钩住UE就会出现错误,然后UE就关闭了。我没做什么呀。
这个dll是通过一个app调用而已
在DEF文件中表明使用了共享的数据
如果是全局钩子需要应用程序触发。要是线程级别的就可以在一个程序里运行。