各位大哥,请问下,我安装的全局消息钩子,我的主程序会把窗口句柄传进去,DLL保存在共享变量(不是全局变量)hWndServer中,这点我能理解,因为DLL会映射到所有进程空间中,且里面的钩子过程会调用PostMessage向我的程序发消息。但是我不明白的是为什么HHOOK hook;放在全局变量程序照样能运行啊,放在共享变量也能运行。要是放在全局变量中,说下我的理解,每个进程不是都有一份私有数据的Private Copy吗,而设置hook是在DLL里的,(代码如下),这是我的程序调用,也就是说只有我的进程hook被初始成了消息钩子句柄了。其它的进程hook应该都没有初始化啊。但是在CallNextHookEx(hook, nCode, wParam, lParam);怎么也能运行成功吗?哪位帮我解释下啊。__declspec(dllexport) BOOL setMyHook(HWND hWnd)
    {
     if(hWndServer != NULL)
return FALSE; // already hooked!
     hook = SetWindowsHookEx(WH_GETMESSAGE,
    (HOOKPROC)msghook,
    hInst,
    0);
     if(hook != NULL)
{ /* success */
 hWndServer = hWnd;
 return TRUE;
} /* success */
     return FALSE; // failed to set hook
    } // setMyHook//以下是DLL里的
#pragma data_seg(".JOE")
HWND hWndServer = NULL;
#pragma data_seg()
#pragma comment(linker, "/section:.JOE,rws")HINSTANCE hInst;
UINT UWM_MOUSEMOVE;
HHOOK hook;
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam);BOOL APIENTRY DllMain( HINSTANCE hInstance, 
                       DWORD  Reason, 
                       LPVOID Reserved
 )
{
 switch(Reason)
    { /* reason */
     case DLL_PROCESS_ATTACH:
hInst = hInstance;
UWM_MOUSEMOVE = RegisterWindowMessage(UWM_MOUSEMOVE_MSG);//return value is a message identifier in the range 0xC000 through 0xFFFF
return TRUE;
     case DLL_PROCESS_DETACH:
if(hWndServer != NULL)
   clearMyHook(hWndServer);
return TRUE;
    } /* reason */
    return TRUE;
}
/****************************************************************************
*                                 setMyHook
* Inputs:
*       HWND hWnd: Window to notify
* Result: BOOL
*       TRUE if successful
* FALSE if error
* Effect: 
*       Sets the hook
****************************************************************************/__declspec(dllexport) BOOL setMyHook(HWND hWnd)
    {
     if(hWndServer != NULL)
return FALSE; // already hooked!
     hook = SetWindowsHookEx(WH_GETMESSAGE,
    (HOOKPROC)msghook,
    hInst,
    0);
     if(hook != NULL)
{ /* success */
 hWndServer = hWnd;
 return TRUE;
} /* success */
     return FALSE; // failed to set hook
    } // setMyHook

/****************************************************************************
*                                 clearMyHook
* Inputs:
*       HWND hWnd: Window hook
* Result: BOOL
*       TRUE if successful
* FALSE if error
* Effect: 
*       Removes the hook that has been set
****************************************************************************/__declspec(dllexport) BOOL clearMyHook(HWND hWnd)
    {
     if(hWnd != hWndServer || hWnd == NULL)
return FALSE;
     BOOL unhooked = UnhookWindowsHookEx(hook);
     if(unhooked)
hWndServer = NULL;
     return unhooked;
    } // clearMyHook

/****************************************************************************
*                                   msghook
* Inputs:
*       int nCode: Code value
* WPARAM wParam:
* LPARAM lParam:
* Result: LRESULT
*       Either 0 or the result of CallNextHookEx
* Effect: 
*       Hook processing function. If the message is a mouse-move message,
* posts the coordinates to the parent window
****************************************************************************/static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)
    {
     if(nCode < 0)
{ /* pass it on */
 CallNextHookEx(hook, nCode, wParam, lParam);
 return 0;
} /* pass it on */
     LPMSG msg = (LPMSG)lParam;
     if(msg->message == WM_MOUSEMOVE ||msg->message == WM_NCMOUSEMOVE)
 PostMessage(hWndServer, UWM_MOUSEMOVE, 0, 0);//先向我们的进程发送消息
     return CallNextHookEx(hook, nCode, wParam, lParam);
    } // msghook