06170249.txt 17-Jun-00


System Hook

Hi folks,

I am experimenting with a system-wide hook and it GPFs.
The hook (in a DLL).
Static Function NoCEHook(nCode as int, wParam as dword,;
  lParam as long) as long CALLBACK
return 1L
The code from my Start() method to set the hook:
  ptrHookDLL:=_VOLoadLibrary("WmHook.DLL")
  if !IsNil(ptrHookDLL)
    lpfn:=GetProcAddress(ptrHookDLL,String2Psz("NoCEHook"))
    if !IsNil(lpfn)
      ptrHook:=SetWindowsHookEx(WH_KEYBOARD,@lpfn,null,0)
      if IsNil(ptrHook)
        //This never shows up, so I guess it's OK.
        WarningBox{,"","HOOK IS NIL"}:Show()
      endif
    endif
  endif
At this point, all is fine.  But as soon as I hit anything
  on the keyboard I get a GPF:

<<<          Stephane Hebert  SIJD        >>>

Stephane,

The Win32 API states:
"An error may occur if the hMod parameter is NULL and the
  dwThreadId parameter is zero or specifies the identifier
  of a thread created by another process."
I'd either try passing the DLL handle as the 3rd parameter
  to SetWindowsHookEx or passing the handle of the current
  thread as the 4th.
Failing that I'd try taking the Static qualifier off your
  function.

Mike Jones

Mike,

This should tell me if the CTRL key is being held down when
  the ESCAPE key is pressed down.
Doesn't work.
The other problem I have is even though I can trap the
  Window Keys, it doesn't prevent Windows from popping up
  the Start Menu, which means that Windows has it's own hook
  for that.
How can I disable that ?
I want to prevent that darn StartMenu to pop up when the
  user presses either CTRL+-ESC or the Window Keys.

Thanks.

Stephane,

I don't know if it's a typo, but SetWindowsHookEx() returns
  NULL or a pointer to a hook. Perhaps it will never be NIL

  type.

Just a thought,
Amilcar A. Camargo

Stephane,

  lpfn:=GetProcAddress(ptrHookDLL,String2Psz("NoCEHook"))
GetProcAddress(...) returns a pointer, so
  ptrHook:=SetWindowsHookEx(WH_KEYBOARD,lpfn,null,0)
instead of
  ptrHook:=SetWindowsHookEx(WH_KEYBOARD,@lpfn,null,0)
should do the trick.

HTH
Frank