home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4759 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!usc!rpi!ghost.dsi.unimi.it!univ-lyon1.fr!chx400!bernina!pkarrer
  3. From: pkarrer@bernina.ethz.ch (Peter Karrer)
  4. Subject: Problem with SetWindowsHookEx
  5. Message-ID: <1993Jan8.202725.19845@bernina.ethz.ch>
  6. Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
  7. Date: Fri, 8 Jan 1993 20:27:25 GMT
  8. Lines: 43
  9.  
  10. I am trying to intercept Windows WM_CREATE, WM_DESTROY etc messages.
  11. Obviously, what I need is a SetWindowsHookEx(WH_CBT or WH_CALLWNDPROC, ..).
  12.  
  13. At first sight, my code works quite well, but...
  14. When I start MS Excel 4.0, it gives me a GPF at 0002:2995 in KRNL386.EXE.
  15. When I start MS Word 2.0a, it gives me a GPF at 00DB:01BD in WINWORD.EXE.
  16. When I start any other application, everything looks fine. This includes
  17. programs that use Windows hooks themselves, like Borland's WinSight.
  18.  
  19. Using SetWindowsHookEx with WH_GETMESSAGE, WH_MSGFILTER etc is no problem,
  20. but these don't intercept the messages I need (WH_DEBUG crashes, however).
  21.  
  22. Am I overlooking something obvious, or is it just that the problematic
  23. applications are from Microsoft? (:-)
  24.  
  25. This is the essential part of my code (TPW 1.0):
  26.  
  27. LIBRARY HookDLL;
  28.  
  29.   USES
  30.     WinProcs, WinTypes, Win31;
  31.  
  32.   VAR
  33.     hookH: HHook;
  34.     hookProcInst: TFarProc;
  35.  
  36.   FUNCTION HookProc(code: INTEGER; wParam: WORD; lParam: LONGINT): LONGINT;
  37.            EXPORT;
  38.   BEGIN {do nothing, just call the next hook}
  39.     HookProc := CallNextHookEx(hookH, code, wParam, lParam);
  40.   END;
  41.  
  42.   {...}
  43.  
  44. BEGIN
  45.   {...}
  46.   hookProcInst := MakeProcInstance(@HookProc, hInstance);
  47.   {Don't think MakeProcInstance is really necessary for EXPORT procs...}
  48.   hookH := SetWindowsHookEx(WH_CBT, THookProc(hookProcInst), hInstance, 0);
  49. END.
  50.  
  51. -- 
  52. Peter Karrer                                   pkarrer@bernina.ethz.ch
  53.