system hook 
Author Message
 system hook

I have an example dll which implements a systemwide hook , and notifies the
client with the following line of code.

SendMessage( g_pHookData->hwndNotify, g_pHookData->nNotifyMsg,
(WPARAM)(HSHELL_WINDOWCREATED==nCode), (LPARAM)wParam );

the following is used by the client to set the hook.

if (!SetShellHook( hwnd, PWM_HOOKMESSAGE ))
        return FALSE; ......

Where g_pHookData is defined as

struct HOOKDATA
{
   HWND  hwndNotify;
   HHOOK hShellHook;
   UINT  nNotifyMsg;

Quote:
};

What I'd like to know is , how best to set up an ATL object to implement the
hook.
The questions I'm asking myself are.
1 Do I HAVE to use a hwnd and sendmessage  ( if not , how else can I
approach it)

assuming I do need a hwnd

2. Do I use a Control and set the windowed property?
3. Can I use CWindow?

As you can probably tell , this is all quite new to me , so any insights are
gratefully recieved.

Yours Paul Felce
MCP VB



Sat, 22 Feb 2003 15:14:33 GMT  
 system hook

You must be aware that the DLL implementing a systemwide hook is loaded into
every process in the system. Thus you have multiple copies of the DLL
executing in the context of different processes. So you must use some form
of interprocess communication (IPC) to exchange data between these instances
of DLL and the main process (the one that installed the hook and is
apparently interested in the hooked messages). SendMessage (PostMessage is
better IMHO) is just one method of IPC. For example, I use a combination of
PostMessage and shared memory allocator based on memory-mapped files (see
CreateFileMapping et al). A KB article Q125677 "HOWTO: Share Data Between
Different Mappings of a DLL" may also be of interest.
--
With best wishes,
    Igor Tandetnik


Quote:
> I have an example dll which implements a systemwide hook , and notifies
the
> client with the following line of code.

> SendMessage( g_pHookData->hwndNotify, g_pHookData->nNotifyMsg,
> (WPARAM)(HSHELL_WINDOWCREATED==nCode), (LPARAM)wParam );

> the following is used by the client to set the hook.

> if (!SetShellHook( hwnd, PWM_HOOKMESSAGE ))
>         return FALSE; ......

> Where g_pHookData is defined as

> struct HOOKDATA
> {
>    HWND  hwndNotify;
>    HHOOK hShellHook;
>    UINT  nNotifyMsg;
> };

> What I'd like to know is , how best to set up an ATL object to implement
the
> hook.
> The questions I'm asking myself are.
> 1 Do I HAVE to use a hwnd and sendmessage  ( if not , how else can I
> approach it)

> assuming I do need a hwnd

> 2. Do I use a Control and set the windowed property?
> 3. Can I use CWindow?

> As you can probably tell , this is all quite new to me , so any insights
are
> gratefully recieved.

> Yours Paul Felce
> MCP VB



Sat, 22 Feb 2003 23:06:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. System hooks?

2. Keyboard System Hook: where?

3. System hooks in NT

4. Generating keypress...after getting input from system hook

5. norton/system hook incompatibility?

6. System hooks in NT

7. 32 bit Global Subclassing win System Hook Proc.

8. System wide Message Hook not working when caller app loses focus

9. Creating system wide keyboard Hooks with c#

10. Hook file-system activity

11. system wide hook

12. CBT Hook & weird system behavior

 

 
Powered by phpBB® Forum Software