views:

188

answers:

1

I am trying to use a global shell hook to listen for windows created and destroyed events, but it seems as though my program is only registering the destroyed event for the local thread. No creation events at all, and definitely not the global events that I think they should be.

I have spent the last day scouring the googles as well as codeguru, codeproject, and msdn, but it looks to me like I'm doing it right, although I am clearly not. Can anybody help point me in the right direction?

#pragma data_seg(".SHARE")
HWND hWndServer = NULL;
HHOOK g_shell_hook = NULL;
#pragma data_seg()
#pragma comment(linker, "/section:.SHARE,RWS")

TASKBAR_API int StartShellHook(HWND hWnd)
{
    g_shell_hook = SetWindowsHookEx(WH_SHELL, ShellProc, g_dll_module_handle, 0);
    if(g_shell_hook)
        hWndServer = hWnd;
    return (g_shell_hook != NULL);
}

Here is my code for hooking into the shell, which all seems to be correct to me, but again, its not giving the proper output. Right now the ShellProc function is just set up to do trivial variable incrementation on windows create and destroy messages, just for a line to put a break point on, but the program only hits the breaks for the destroy message of the local window. again, any help would be fantastic, thank you very much in advance.

A: 

One reason that this might happen, is that you've compiled a 32-bit DLL and you're trying to run it on a 64-bit OS. In general though, what are you trying to accomplish by installing this hook? Hooks are hard to get right, and are subject to being deregistered should you take too long in the handler.

Paul Betts
I am compiling a 32-bit DLL, but I am also on a 32-bit OS, so that should not be the problem. I am trying to write an add on for RocketDock that acts like the windows taskbar in that it shows you what programs you have running, even if RocketDock does not already have a shortcut to that program, and even if the program is not minimized. If there is a better way to achieve this goal, I am all ears, but there seems to be surprisingly little information about this kind of thing on the internet.
etna