In this particular mousehook i've hooked WM_LBUTTONDOWN and got it to post the coordinates of the clicks to my program.
However, the coordinates are only saved when a click occurs in my window, although i've set a system-wide hook. Im puzzled. Thanks.
However, the coordinates are only saved when a click occurs in my window, although i've set a system-wide hook. Im puzzled. Thanks.
First guess is that the hook is not inside a DLL.
Any more information..?
Any more information..?
Ok, I apologise for the delay, work has been hectic. The problem as previously stated is that ive set a global hook however only left button clicks that occur from within my dialog are recorded. Im uncertain why this is the case.
dl;
exe;
rc;
dl;
.486
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
MouseProc PROTO :DWORD, :DWORD, :DWORD
InstallHook PROTO :DWORD
.data?
hInstance dd ? ;Dll's module handle
hHook dd ? ;Hook handle
hWnd dd ?
.const
WM_MOUSEHOOK equ WM_USER+6
.code
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
mov eax,hInst
mov hInstance,eax
.IF reason== DLL_THREAD_DETACH || reason== DLL_PROCESS_DETACH
.IF hHook
invoke UnhookWindowsHookEx,hHook
.ENDIF
.ENDIF
mov eax,TRUE
ret
DllEntry Endp
InstallHook proc hwnd:DWORD
push hwnd
pop hWnd
invoke SetWindowsHookEx, WH_MOUSE, OFFSET MouseProc, hInstance, 0
mov hHook,eax
ret
InstallHook endp
MouseProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD
invoke CallNextHookEx,hHook,nCode,wParam,lParam
mov edx,lParam
assume edx:PTR MOUSEHOOKSTRUCT
mov ebx, wParam
.IF ebx == WM_LBUTTONDOWN
Invoke PostMessage, hWnd, WM_MOUSEHOOK, .pt.x, .pt.y
.ENDIF
assume edx:nothing
xor eax,eax
ret
MouseProc endp
End DllEntry
exe;
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
WndProc PROTO :HWND, :DWORD, :DWORD, :DWORD
;---------------------
;
.data
DllName db 'DLL.dll',0
szInstallHook db 'InstallHook',0
szFormat db "(%d, %d)", 0
;---------------------
;
.data?
hInstance HINSTANCE ?
pInstallHook dd ?
hHookDll dd ?
hHook dd ?
hList dd ?
;---------------------
;
.const
IDD_DIALOG = 1000
IDC_EXIT = 1001
IDC_LISTBOX = 1002
WM_MOUSEHOOK equ WM_USER+6
;---------------------
;
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam, hInstance, IDD_DIALOG, NULL, OFFSET WndProc, NULL
invoke ExitProcess, eax
WndProc proc uses ebx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL szBuffer[128]:byte
.if uMsg == WM_INITDIALOG
INVOKE SetWindowPos, hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
Invoke GetDlgItem, hWnd, IDC_LISTBOX
mov hList, eax
invoke LoadLibrary,OFFSET DllName
mov hHookDll, eax
invoke GetProcAddress,hHookDll,OFFSET szInstallHook
mov pInstallHook,eax
push hWnd
call pInstallHook
mov hHook,eax
.elseif uMsg == WM_MOUSEHOOK
mov eax, wParam
mov ebx, lParam
Invoke wsprintf, ADDR szBuffer, ADDR szFormat, eax, ebx
invoke SendMessage, hList, LB_ADDSTRING,0, ADDR szBuffer
Invoke SendMessage, hList, WM_VSCROLL, SB_BOTTOM, 0
.elseif uMsg == WM_COMMAND
.if wParam == IDC_EXIT
JMP thedoor
.endif
.elseif uMsg == WM_CLOSE
thedoor:
invoke FreeLibrary,hHookDll
invoke ExitProcess, 0
.endif
xor eax,eax
ret
WndProc endp
end start
rc;
;This Resource Script was generated by WinAsm Studio.
#define IDC_EXIT 1001
#define IDD_DIALOG 1000
#define IDC_LISTBOX 1002
IDD_DIALOG DIALOGEX 10,10,137,101
CAPTION "WH_MOUSE Example"
FONT 0,""
STYLE 0x10ca0880
EXSTYLE 0x00000000
BEGIN
CONTROL "EXIT",IDC_EXIT,"Button",0x50010000,2,82,134,18,0x00000000
CONTROL "",IDC_LISTBOX,"ListBox",0x50010140,3,2,133,78,0x00000200
END
Going by the example code in the SDK, you should
- use LoadLibrary to load your DLL
- use GetProcAddress to get the address of the mouse hook proc
- pass that address to SetWindowsHookEx along with the DLL hmod
and do all that from your EXE, not the DLL.
- use LoadLibrary to load your DLL
- use GetProcAddress to get the address of the mouse hook proc
- pass that address to SetWindowsHookEx along with the DLL hmod
and do all that from your EXE, not the DLL.