﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
1979	_WinAPI_SetWindowsHookEx() Don`t work with all idHook	monoscout999	Gary	"_WinAPI_SetWindowsHookEx() only works when the idHook parameter is $WH_KEYBOARD_LL or $WH_MOUSE_LL and not when the idHook parameter is another as $WH_CALLWNDPROCRET for example.
{{{
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>

Opt('MustDeclareVars', 1)

Global $hHook, $hStub_CallWndRetProc, $buffer = """"

_Main()

Func _Main()
	OnAutoItExitRegister(""Cleanup"")

	Local $hmod

	$hStub_CallWndRetProc = DllCallbackRegister(""_CallWndRetProc"", ""long"", ""int;wparam;lparam"")
	$hmod = _WinAPI_GetModuleHandle(0)
	$hHook = _WinAPI_SetWindowsHookEx($WH_CALLWNDPROCRET, DllCallbackGetPtr($hStub_CallWndRetProc), $hmod)
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hHook = ' & $hHook & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

	While 1
		Sleep(10)
	WEnd
EndFunc   ;==>_Main

;===========================================================
; callback function
;===========================================================
Func _CallWndRetProc($nCode, $wParam, $lParam)
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $nCode = ' & $nCode & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
	local $tagCWPRETSTRUCT = ""LRESULT lResult;LPARAM lParam;WPARAM wParam;UINT message;HWND hwnd;""
	Local $tCWPRETSTRUCT = DllStructCreate($tagCWPRETSTRUCT, $lParam)
	If $nCode < 0 Then
		Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
	EndIf
	If DllStructGetData($tCWPRETSTRUCT, ""message"") = $WM_MOUSEMOVE Then
		ConsoleWrite(""Mouse Move Message Recived by - "" & DllStructGetData($tCWPRETSTRUCT, ""hwnd"") & @CRLF)
	EndIf
	Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
	_WinAPI_UnhookWindowsHookEx($hHook)
	DllCallbackFree($hStub_CallWndRetProc)
EndFunc   ;==>Cleanup
}}}
"	Bug	closed		Standard UDFs	3.3.6.1	None	No Bug	Hooks, Hook	
