写了一个钩子函数,但每次钩到其他进程后,那个进程就会报错关闭.哪里错了?钩子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给关掉,我也没做什么呀,帮忙看看.
(没分了,先给这些吧)

解决方案 »

  1.   

    The OutputDebugString function sends a string to the debugger for the current application
    你试一下把OutputDebugString注释看看呢
    LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam) 

    //OutputDebugString("Receive msg"); 
    return (CallNextHookEx(g_hhook,nCode,wParam,lParam)); 

      

  2.   

    一样不行
    我把所有的OutputDebugString都去掉了,但还是报错Uedit32.exe 中的 0x174a12a8 处未处理的异常: 0xC0000005: 读取位置 0x174a12a8 时发生访问冲突 。只要钩住UE就会出现错误,然后UE就关闭了。我没做什么呀。
      

  3.   

    你是用的全局钩子,全局钩子必须放到dll中,你写个dll试试吧
      

  4.   

    是放到dll里的,钩子函数部分是dll.(第一个程序块就是dll中的)
    这个dll是通过一个app调用而已
      

  5.   

    请问共享数据块是放在DLL中还是放在应用程序中?
      

  6.   

    在DLL中设置共享的数据区 
    在DEF文件中表明使用了共享的数据
    如果是全局钩子需要应用程序触发。要是线程级别的就可以在一个程序里运行。