system wide hook 
Author Message
 system wide hook

Hi, could someone please let me have a look at some sample codes on how to
setup a WH_GETMESSAGE hook? I have tried vainly to create a dll file and a
win32 application, but they will never work when I call the SetWindowsHookEx
with the following parameters:

WH_GETMESSAGE, GetMsgProc, (HINSTANCE)hLibrary, 0

Where GetMsgProc is in a dll, and I used LoadLibrary function to get the
handle to that dll. The weird thing is that when I change the parameters to
the following, it works wonderfully:

WH_GETMESSAGE, GetMsgProc, NULL, GetCurrentThreadId()

I know the above parameters do not setup a system wide hook... but did I
make some mistakes on setting up a system wide hook? Could someone please
enlighten me on this because I have been stucked on this problem for almost
4 days.

If possible, I could supply my source codes..

Thank you,
Mike



Thu, 11 Sep 2003 15:54:59 GMT  
 system wide hook

Quote:
>Hi, could someone please let me have a look at some sample codes on how to
>setup a WH_GETMESSAGE hook? I have tried vainly to create a dll file and a
>win32 application, but they will never work when I call the SetWindowsHookEx
>with the following parameters:

>WH_GETMESSAGE, GetMsgProc, (HINSTANCE)hLibrary, 0

>Where GetMsgProc is in a dll, and I used LoadLibrary function to get the
>handle to that dll.

Mike,
It sounds like you're doing the right thing. When you say it doesn't
work, is SetWindowsHookEx returning a failure - and if so, what does
GetLastError tell you the problem is?

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 11 Sep 2003 21:15:12 GMT  
 system wide hook

Quote:
>     I tried using GetLastError to see what's the problem and it says
>invalid window handle.

Mike,

There doesn't appear to be anything wrong with your hook code, your
mistake seems to be that you're not checking that the hook has worked.
You should do this:

    hLibrary = LoadLibrary(TEXT("myDll.DLL"));
    ghMyHook = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
                        (HINSTANCE) hLibrary, 0);
    if ( ghMyHook == NULL )
    {
        /* It's failed */

You also need to initialise the data that you're intending to share -
the data_seg pragma applies only to initialized data ...

#pragma data_seg ("shared")
HWND ghHwnd = NULL;
SETSTR pfn = NULL;
HHOOK ghHook = NULL;
#pragma data_seg()

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Tue, 16 Sep 2003 18:31:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Obtaining HWND in system wide hook DLL?

2. How to setup system-wide hook for Common Dialogs

3. System wide hook problem...

4. ShellExecute() seems to unhook system wide hook...

5. System wide hook question...

6. How to install System Wide Hooks, Sample code included working for installing app

7. system-wide hook?

8. Obtaining HWND in system wide hook DLL?

9. any books or esamples on system wide hooks

10. system wide hooks

11. System-Wide-Hook-Problem

12. Problems with System wide hooks and Windows 95

 

 
Powered by phpBB® Forum Software