Re: SetWindowsHookEx and external thread problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: sklett (asasd_at_asdfasdfsd.com)
Date: 11/11/04


Date: Thu, 11 Nov 2004 10:27:19 -0800

Now I have the hook installed, but the handler never fires. This stuff is
crazy. Basically, I have it working fine when I pass NULL for the threadID,
but when I pass a valid, external threadID it stops working.

 //
 // insert into another process
 //
 HWND HmbWindow = FindWindow(NULL, "Untitled - Notepad");
 if(HmbWindow == NULL)
 {
  OutputDebugString("Failed getting window handle\n");
 }
 long threadID = GetWindowThreadProcessId(HmbWindow, NULL);

 hKeyHook = SetWindowsHookEx (WH_KEYBOARD, lpfnHookProc, hInstance,
threadID/*NULL*/);

"sklett" <asasd@asdfasdfsd.com> wrote in message
news:uIM$sUByEHA.3844@TK2MSFTNGP09.phx.gbl...
> ** This is a continuation of an older thread, but I thought starting over
> would be better as things have been tidied up...
>
> I have created a dll to install and handle my hook and I have created a
test
> application that will utilize this new hook. The call to SetWindowHookEx
> works fine when the threadID parameter is NULL, but when I specify a
> specific thread ID obtained from a call to GetWindowThreadProcessId the
call
> to SetWindowHookEx returns NULL.
>
> I have NO idea where to start debuggin this, Does anyone have any ideas?
>
>
> Thanks,
> Steve
>
>



Relevant Pages

  • Re: Hooking problem...
    ... You are trying to install a hook to a thread which is not created by your ... In this case your hook procedure has to be in a DLL because what ... > threadId = API.GetWindowThreadProcessId; ... > private IntPtr MsgHookProc ...
    (microsoft.public.dotnet.languages.csharp)
  • SetWindowsHookEx and external thread problem
    ... ** This is a continuation of an older thread, ... I have created a dll to install and handle my hook and I have created a test ... The call to SetWindowHookEx ... I have NO idea where to start debuggin this, ...
    (microsoft.public.vc.mfc)