Hello !

The following code makes my program crash, but i cannot find the error!
When i replace WH_CALLWNDPROC with WH_KEYBOARD_LL, everything works fine. I'm running Windows XP.


.486
.model flat,stdcall
include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
myHookProc PROTO :DWORD,:DWORD,:DWORD

.data?
hInstance dd ? ; Instanz-Handle des Programms
hHook dd ?

.code
START:
invoke GetModuleHandle,0
mov hInstance,eax
invoke SetWindowsHookEx,WH_CALLWNDPROC,addr myHookProc,hInstance,0
mov hHook, eax
invoke MessageBox,0,0,0,0
invoke UnhookWindowsHookEx,hHook
invoke ExitProcess,0

myHookProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD
invoke CallNextHookEx,0,nCode,wParam,lParam
ret
myHookProc endp
end START



Thanks alot for any answer, see you !!
Posted on 2003-02-15 21:43:48 by LordHelmchen
.486

.model flat,stdcall
include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
myHookProc PROTO :DWORD,:DWORD,:DWORD

.data?
hInstance dd ? ; Instanz-Handle des Programms
hHook dd ?

.code
START:
invoke GetModuleHandle,0
mov hInstance,eax
[color=red]invoke GetCurrentThreadId[/color]
invoke SetWindowsHookEx,WH_CALLWNDPROC,addr myHookProc,hInstance,[color=red]eax[/color]
mov hHook, eax
invoke MessageBox,0,0,0,0
invoke UnhookWindowsHookEx,hHook
invoke ExitProcess,0

myHookProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD
invoke CallNextHookEx,[color=red]hHook[/color],nCode,wParam,lParam
ret
myHookProc endp
end START


If you want to set a global hook your gonna have to put it inside a dll, your exe cannot be mapped into the address space of other processes to receive the notifications.
Posted on 2003-02-16 05:28:07 by BubbaFate
hello BubbaFate, thanks for your answer.
But why does the global keyboard hook work then? and the global mouse hook works too. :(



i am actually trying to hinder a program to do a SetForegroundWindow in an infinite loop, cause that forbits my own window to become topmost.

See you!
Posted on 2003-02-16 08:38:18 by LordHelmchen
MSDN Platform SDK
All global hook functions must be in libraries.
How do you know the global mouse/keyboard hooks are indeed working? Just because they dont crash the system doesn't mean they are working...
Posted on 2003-02-16 08:44:59 by BubbaFate
As far as making your app topmost, I have never had a situation where setting HWND_TOPMOST doesn't make my app the topmost window... Now if you have two topmost windows then which ever one is in focus will be on top... if you have some app that you dont want to do that then just change its style to HWND_NOTOPMOST
Posted on 2003-02-16 08:49:51 by BubbaFate
hello BubbaFate, thanks for your quick replies !

The keyboard/mouse hooks are working; i did a "invoke Beep,100,100" to verify if an event occured.


The topmost problem is that i'm trying to create an application that shows status information like IsConnected and KB/s and stuff when a hotkey is pressed. This is especially useful in computergames. Some of these games try to avoid beeing overlapped using that infinit SetForegroundWindow loop.
My latest idea was now to capture the occuring window messages whenever that other application sets itself to ForegroundWindow and then alter the message. But as i mentioned, that makes my app crash! :confused:


See you !
Posted on 2003-02-16 09:23:03 by LordHelmchen
Well, in order to install a global windowproc hook it must be in a dll. Even if you have a hook installed I doubt you will be able to prevent the game from calling setforegroundwindow... Ive never used it, but have you looked into LockSetForegroundWindow? Maybe it will help you... unfortunately its not available on windows 9x
Posted on 2003-02-16 09:40:30 by BubbaFate
hi BubbaFate!

I already tried using LockSetForegroundWindow after i created my own window and set it topmost. but it didnt work.
Now im frustrated because that problem seems to prevail. :mad:


Thanks anyway, see you !
Posted on 2003-02-16 10:28:59 by LordHelmchen