The good news is, I'm trying to develop a generic hook library source, that I'm posting here. The basic idea is that you only code the hook handlers and include them in the source, then build the dll, and it's ready to use. It exports procedures to set and remove hooks, and also has one-instance code too.

Note: you have to build the library using the "makeit.bat" file included in the attachment, so the shared section will be linked correctly.

Now for the bad news, it doesn't work... :rolleyes:

In my test program, the hook is installed without errors. However, I'm not receiving any messages.

Any help? :(

EDIT: Attachment deleted to save space (56 downloads). See bottom of thread.
Posted on 2003-07-25 13:26:10 by QvasiModo
little mistake
assume ebx:ptr HOOK

align DWORD
SetHook proc uses ebx hwnd,hook

mov eax,hook
cmp eax,MIN_HOOK
jl notsupp
cmp eax,MAX_HOOK
jg notsupp
[b] inc eax ; !!! you change value hook[/b]
lea edx,[offset apHookProc + (eax * 4)]
lea ebx,[offset aHookData + (eax * 4)]
mov ecx,[edx]
jecxz notsupp
cmp [ebx].hWnd,0
jne already
cmp [ebx].hHk,0
jne already
m2m [ebx].hWnd,hwnd
[b] dec eax ; !!! need restore[/b]
mov [ebx].hHk,$invoke (SetWindowsHookEx,eax,ecx,hInst,0)
test eax,eax
jnz quit
mov [ebx].hWnd,eax

call SetLastError
xor eax,eax
jmp short quit

jmp short quiterr

jmp short quiterr

SetHook endp
Posted on 2003-07-27 23:39:43 by P2M
First of all, I'd like to apologize for posting such a quick one-afternoon hack. It's just that I knew I'de be tied up for this weekend so I posted quickly and without proper bug checking...

Anyway, thanks P2M. I had also found the bug on my own, and a few more (like that nasty typo in the mouse hook handler, I typed "edx" instead of "eax" in the PostMessage call). I'm posting here a corrected, fully working version, and some sample code too. It should be bug free by now. :)

I still couldn't make the RadASM project build correctly, though. But working on it.

I was also trying to make the definition of the apHookProc array a little more flexible, by using macros, but I failed. I'll post that in another thread in the Main forum.

I'm also working in another version, to be used from other programming languages (like C for example). I'll post it when it's finished.

EDIT: Updated. With donkey's help, I got the RadASM project to work correctly.

EDIT: Attachment deleted to save space (27 downloads). See bottom of thread.
Posted on 2003-07-28 09:39:08 by QvasiModo
New version: 1.01

- New method of adding your hook handlers. Now it uses macros, so you don't have to worry about setting the correct number of NULLs.
- Added a new sample program showing how to use CBT hooks to block or allow minimizing and maximizing of windows.
- Small bugfixes.

EDIT: Attachment deleted to save space. 86 downloads.
Posted on 2003-07-29 13:46:14 by QvasiModo
Version 1.02

- Improved resource cleanup on exit. Now it is not mandatory to call HLCleanup on exit.
Thanks to Donkey for the idea. :)
Posted on 2003-12-11 14:17:37 by QvasiModo