我用全局的钩子函数处理了截获到的系统消息,现在我想在处理完后通知引用该dll的主程序,请问我该用什么办法呢?

解决方案 »

  1.   

    1.如果是全局钩子,则系统所有进程都将加载此dll,不知你所说的引用该dll的程序是什么意思。
    2.如果你是指加载hook的进程,那在具有share属性的segment里加入一HWND变量,在加载hook时保存此句柄,并在HookProc里向此句柄发自定义的消息即可。
      

  2.   

    在设置hook的时候,把 exe的窗口hWnd 传进去,
    然后用SendMessage(HWND ,MESSAGE,WPARAM,LPARAM);
    向该接收窗口的exe发送message,在exe中,做一个message 响应函数负责接收!
      

  3.   

    问题是我的主程序没有应用MFC,不是个窗口类,sendmessage用不了啊。
      

  4.   

    SendMessage这么用
    The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message. To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
    SyntaxLRESULT SendMessage(          HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam
    );
    ParametershWnd
    [in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
    Msg
    [in] Specifies the message to be sent.
    wParam
    [in] Specifies additional message-specific information.
    lParam
    [in] Specifies additional message-specific information.
    Return ValueThe return value specifies the result of the message processing; it depends on the message sent.
    ResApplications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.The system only does marshalling for system messages (those in the range 0 to WM_USER). To send other messages (those above WM_USER) to another process, you must do custom marshalling. If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. For more information on nonqueued messages, see Nonqueued Messages. Windows 95/98/Me: SendMessageW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems. 
      

  5.   

    有人告诉我这样处理,在WinMain之中调用GetCurrentThreadId(),得到当前线程的ID,在dll里处理完截获的消息以后,用PostThreadMessage来通知主程序,可是,该怎么自定义消息才能让dll和主程序都识别呢?另外在主程序里,该怎样时刻监视是否有消息发送过来呢?因为不是MFC的窗口,所以也不能调用PreTranslateMessage来处理该消息。
      

  6.   

    用peekmessage在主程序中建立消息循环,然后判断是否是自定义消息。
      

  7.   

    you write a function in the dll
    such as 
    void GetHwnd(HANDLE hwnd)
    {
    g_handle=hwnd;
    }
    you use the function  in the *.exe and in the dll you can write SendMessage(g_hwnd,.....)
    OK?