.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
MessageProc proto nCode:DWORD, wParam:WPARAM, lParam:LPARAM
.const
MM_CHAR equ WM_USER + 432
.data
hInst dd 0
.data?
hhk dd ?
hwnd dd ?
.code
DllEntry proc hInstance:DWORD, dwReason:DWORD, dwReserved:DWORD
.if dwReason == DLL_PROCESS_ATTACH
push hInstance
pop hInst
.endif
mov eax, TRUE
ret
DllEntry Endp
SetHook proc hWnd:DWORD
push hWnd
pop hwnd
invoke SetWindowsHookEx, WH_GETMESSAGE, MessageProc, hInst, NULL
mov hhk, eax
ret
SetHook Endp
UnHook proc
invoke UnhookWindowsHookEx, hhk
ret
UnHook Endp
MessageProc proc nCode:DWORD, wParam:WPARAM, lParam:LPARAM
mov edx, lParam
assume edx:ptr MSG
.if [edx].message == WM_CHAR
invoke PostMessage, hwnd, MM_CHAR, [edx].wParam, [edx].hwnd
.endif
invoke CallNextHookEx, hhk, nCode, wParam, lParam
MessageProc Endp
End DllEntry
compile command line:
\masm32\bin\ml /c /coff MsgHook.asm
\masm32\bin\Link /section:.bss,S /SUBSYSTEM:WINDOWS /DLL /DEF:MsgHook.def MsgHook.obj
I do as Iczelion said, but why it can't work.
when I call "SetHook", it return the handle of hook, but I call "UnHook", it return FALSE, why ?
in fact, I don't understand why "/section:.bss,S", it's ".bbs", but in codes, it's .data:
.data?
hhk dd ?
hwnd dd ?
oh, MessageProc lost a instruction: ret
ha ha, I am so careless.
Thank you, everybody.
Quote
UnHook proc
invoke UnhookWindowsHookEx, hhk
ret
UnHook Endp
Why do u wrap simple functions with more simple functions? Maybe I am missing something , but I think it just makes everything slower and less clear when trying to understand the code.
realcr.
I think his idea is a good one, start simple so it is easy to see where the mistakes are. Once he gets a grip on how it works, it will be on to bigger and better things.
Paul
QuoteWhy do u wrap simple functions with more simple functions?
You must know that it's a DLL project, EXE may not know the handle of hook(hhk), so I must encapsullation a export function for EXE call.