🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #2616

Problem with SetWindowsHookEx

#2616
From: Peter Karrer
Date: Fri, 08 Jan 1993 20:27
43 lines
1887 bytes
I am trying to intercept Windows WM_CREATE, WM_DESTROY etc messages.
Obviously, what I need is a SetWindowsHookEx(WH_CBT or WH_CALLWNDPROC, ..).

At first sight, my code works quite well, but...
When I start MS Excel 4.0, it gives me a GPF at 0002:2995 in KRNL386.EXE.
When I start MS Word 2.0a, it gives me a GPF at 00DB:01BD in WINWORD.EXE.
When I start any other application, everything looks fine. This includes
programs that use Windows hooks themselves, like Borland's WinSight.

Using SetWindowsHookEx with WH_GETMESSAGE, WH_MSGFILTER etc is no problem,
but these don't intercept the messages I need (WH_DEBUG crashes, however).

Am I overlooking something obvious, or is it just that the problematic
applications are from Microsoft? (:-)

This is the essential part of my code (TPW 1.0):

LIBRARY HookDLL;

  USES
    WinProcs, WinTypes, Win31;

  VAR
    hookH: HHook;
    hookProcInst: TFarProc;

  FUNCTION HookProc(code: INTEGER; wParam: WORD; lParam: LONGINT): LONGINT;
           EXPORT;
  BEGIN {do nothing, just call the next hook}
    HookProc := CallNextHookEx(hookH, code, wParam, lParam);
  END;

  {...}

BEGIN
  {...}
  hookProcInst := MakeProcInstance(@HookProc, hInstance);
  {Don't think MakeProcInstance is really necessary for EXPORT procs...}
  hookH := SetWindowsHookEx(WH_CBT, THookProc(hookProcInst), hInstance, 0);
END.

-- 
Peter Karrer                                   pkarrer@bernina.ethz.ch
Technical Details
Message-ID: <1993Jan8.202725.19845@bernina.ethz.ch>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!usc!rpi!ghost.dsi.unimi.it!univ-lyon1.fr!chx400!bernina!pkarrer

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!usc!rpi!ghost.dsi.unimi.it!univ-lyon1.fr!chx400!bernina!pkarrer
From: pkarrer@bernina.ethz.ch (Peter Karrer)
Subject: Problem with SetWindowsHookEx
Message-ID: <1993Jan8.202725.19845@bernina.ethz.ch>
Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
Date: Fri, 8 Jan 1993 20:27:25 GMT
Lines: 43