home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / M2V11-1.LHA / modula / examples / src / Hook.mod < prev    next >
Encoding:
Text File  |  1994-10-03  |  1.2 KB  |  38 lines

  1. MODULE Hook ;
  2.  
  3. FROM SYSTEM IMPORT ADDRESS, ADR ;
  4. IMPORT U := Utility{36}, Dos{36} ;
  5.  
  6. (* This simple function is used to initialize a Hook *)
  7.  
  8. PROCEDURE InitHook ( VAR h : U.Hook ; func : U.HOOKFUNC ; data : ADDRESS ) ;
  9. BEGIN (* Fill in the Hook fields *)
  10.   h.h_Entry := U.HookEntry;
  11.   h.h_SubEntry := func ;
  12.   h.h_Data := data ;
  13. END InitHook ;
  14.  
  15. (* This function only prints out a message indicating that we are inside      *)
  16. (* the callback function.                              *)
  17. (* The '@G' comment obtains access to the global data segment (for this       *)
  18. (* procedure only), this is the same as the DICE '__geta4' qualifier          *)
  19. (* Any procedure that is the entry point of an OS callback              *)
  20. (* (eg Hook functions, argument of CreateTask etc) must fetch the global      *)
  21. (* variable pointer or otherwise crash.                          *)
  22. (* NB: Any program that does this can not be made resident (linking will fail)*)
  23.  
  24. PROCEDURE (* @G *)
  25.       MyFunction ( VAR h : U.Hook ; o : ADDRESS ; msg : ADDRESS ) : LONGINT;
  26. BEGIN
  27.   Dos.Printf( "Inside Hook.MyFunction(%ld,%ld)\n", o, msg ) ;
  28.   RETURN 1
  29. END MyFunction ;
  30.  
  31. VAR
  32.    h : U.Hook ;
  33.  
  34. BEGIN
  35.   InitHook( h, U.HOOKFUNC( MyFunction ), NIL) ;
  36.   U.CallHookPkt( ADR(h), 42, 43)
  37. END Hook.
  38.