Making a global hook with this code:

.data
hNextHook  Dd 0

.code
GetMsgProc     Proc Code:DWORD, wParam:DWORD, lParam:DWORD

  invoke CallNextHookEx, hNextHook, Code, wParam, lParam
  ret
GetMsgProc     Endp

invoke SetWindowsHookEx, WH_GETMESSAGE, ADDR 
GetMsgProc, 0, 0
mov    hNextHook, eax
Making segment .data shared and putting it to the DLL. But this doesn't work! What can be wrong?
Posted on 2001-06-10 02:04:00 by CHEMI$T
how are you setting the hook exactly? where is the dll entry point? you can't just dump code inside a dll.. look at iczelion's tutorials.
Posted on 2001-06-10 05:08:00 by fresh
All made as it must be. DllMain works perfectly, functions are working, but the hook code is not called. I wrote a code which is in the function(inside a DLL)and which is called from my exe file to set hook. Here it is:

HookApps Proc
  invoke SetWindowsHookEx, WH_GETMESSAGE, ADDR GetMsgProc, 0, 0
  mov    hNextHook, eax
  ret
HookApps Endp
And that's all! I don't understand what can be wrong!!!
Posted on 2001-06-10 06:09:00 by CHEMI$T
I think you have to install global hook with this way:

.data
dwHinst dword 0
dwHhook dword 0
.code
DllMain proc hinst: dword, reason : dword, unused : dword
    .if reason == DLL_PROCESS_ATTACH
        push hinst ; <--
        pop dwHinst ; <--
    .elseif reason == DLL_PROCESS_DETACH
        invoke UnhookWindowsHookEx, dwHhook
    .endif
    mov eax, TRUE
    ret
DllMain endp

HookApps Proc
  invoke SetWindowsHookEx, WH_GETMESSAGE, ADDR GetMsgProc, dwHist, 0 ;look at the third parameter
  mov dwHhook, eax
  ret
HookApps Endp
Posted on 2001-06-10 22:16:00 by vkim
Thanx vkim, it worked ;)
Posted on 2001-06-11 21:39:00 by CHEMI$T