home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / MKHOOK1.ZIP / HOOK_DLL.ASM < prev    next >
Assembly Source File  |  1992-09-05  |  4KB  |  97 lines

  1. ;---------------------------------------------------------------------------;
  2. ; M.F.Kaplon  Begun:Tue  07-14-1992  Revised:Sat  09-05-1992
  3. ; Title : hook_dll.asm
  4. ;
  5. ; This is the dll to be used with hook_kb.asm
  6.  
  7. ; Its purpose is to test the system message stream for WM_CHAR
  8. ; and when selected keys are struck to post a message to hook_kb
  9. ;
  10. ; The function InputHook monitors the System message queue and responds
  11. ; whenever the WinGetMsg or WinPeekMsg is about to return a message.
  12. ;
  13. ; This is assembled and linked as dll by calling   dll-w386  hook_dll
  14. ;
  15. ; this cmd file also moves the created dll to  c:\os2\dll
  16. ;
  17. ; This program Posts a Message to hook_kb,exe when a message to
  18. ; WM_CHAR is detected. It uses WM_USER+200h as the message ID
  19. ; and the mp1,mp2 parameters of the WM_CHAR message.
  20. ;
  21. ;---------------------------------------------------------------------------;
  22. ;
  23. ;------------------ PRELIMINARIES ----------------------
  24.  
  25. .386             ;preceeding .MODEL makes USE32 default
  26. .MODEL           FLAT,SYSCALL,OS_OS2
  27.  
  28. INCL_DOSMEMMGR      equ  1
  29. INCL_WINERRORS      equ  1
  30. INCL_WIN            equ  1
  31. INCLUDE         c:\toolkt20\asm\os2inc\os2def.inc ;structure defns includes POINTL
  32. INCLUDE         c:\toolkt20\asm\os2inc\pmwin.inc  ;structure defns POINTL defn required
  33. INCLUDE         c:\toolkt20\asm\os2inc\bsememf.inc  ;memory
  34. INCLUDE         c:\toolkt20\asm\os2inc\pmerr.inc  ;errors
  35. INCLUDELIB      c:\toolkt20\os2lib\os2386.lib     ;Library
  36.  
  37. INCLUDE         doswin32.mac      ;macros for calls
  38.  
  39. .STACK    2048
  40.  
  41. .DATA
  42. ;------------- handles --------
  43. jr_hab            DWORD   ?    ;Anchor block handle
  44. hook              DWORD   ?    ;Handle of hook-kb
  45.  
  46. ;------------ structures
  47. jr_qmsg           DWORD   ?    ;Address of Journal Record Message structure
  48.  
  49. ;----Shared Memory Variables---
  50. SharedMem      DWORD  0     ;base address returned
  51. SharedMemName   BYTE  "\SHAREMEM\DATAE.DAT",0
  52. SharedMemFlags DWORD  12h   ;(PAG_COMMIT OR OBJ_GETTABLE OR PAG_WRITE)
  53.  
  54. .CODE
  55.  
  56. ;----------  ESTABLISH InputHook --------------
  57. ;Has the form BOOL EXPENTRY InputHook(HAB hab, PQMSG pQmsg,ULONG fs)
  58. ;QMSG TRUCT  has  following parms as offsets
  59. ;offset 0 hwnd ,offset 4 msg ,offset 8 mp1 ,offset 12 mp2 ,etc.
  60. ;fs contains flags from WinPeekMsg function
  61. InputHook     proc
  62.     push   ebp                  ;return address = 4 bytes,this push = 4 bytes
  63.     mov    ebp,esp              ;so first parameter is 8 bytes from top
  64.     mov    eax,[ebp+8]          ;hab
  65.     mov    jr_hab,eax           ;anchor block handle
  66.     mov    eax,[ebp+12]         ;address of qmsg truct
  67.     mov    jr_qmsg,eax          ;store address of QMSG STRUCT structure
  68.     ;---- GET ADDRESS OF SHARED MEMORY ---
  69.     .IF SharedMem == 0
  70.        $Call DosGetNamedSharedMem,offset SharedMem,offset SharedMemName,1
  71.        .IF eax != 0
  72.           $Alarm    ;$WinErrMsg " : DosAllocSharedMem"
  73.        .ENDIF
  74.        ;---- Get handle of hook_kb and Release Shared Memory ----
  75.        mov   edi,SharedMem
  76.        mov   eax,[edi]
  77.        mov   hook,eax              ;now has handle of hook-kb
  78.        $Call DosFreeMem,SharedMem  ;release since no longer needed
  79.        .IF eax != 0
  80.           $Alarm    ;$WinErrMsg " : DosAllocSharedMem"
  81.        .ENDIF
  82.     .ENDIF
  83.     ;---- IF WM_CHAR MESSAGE DETECTED -----
  84.     mov  esi,jr_qmsg
  85.     .IF dword ptr [esi+4] == WM_CHAR
  86.          ;------ NOW [esi+8]=mp1  [esi+12]=mp2 ------
  87.          $Call WinPostMsg,hook,WM_USER+200h,[esi+8],[esi+12]
  88.     .ENDIF
  89. xxout:
  90.     mov    esp,ebp              ;restore  stack pointer
  91.     pop    ebp                  ;back to  way it was at entrance
  92.     mov    eax,FALSE            ;pass to next hook in chain
  93.     ret
  94. InputHook  endp
  95.  
  96. END
  97.