Jump to content

DllCallbackRegister? D:

Recommended Posts

search in the forum you wil find a lot of good examples.


#include <winapi.au3>
#include <guitooltip.au3>
#include <WindowsConstants.au3>
$hTool = _WinAPI_CreateWindowEx($WS_EX_TOPMOST, "tooltips_class32", 0, BitOR($TTS_ALWAYSTIP, $TTS_NOPREFIX, $TTS_BALLOON), 0, 0, 0, 0, 0)
_GUIToolTip_AddTool($hTool, 0, "CPU Info:", 0, 0, 0, 0, 0, 16 + 128, 0) ; 16 = TTF_TRACK, 128 = TTF_PARSELINKS
_GUIToolTip_SetTitle($hTool, "CPU Info:", 1)

$m_callback = DllCallbackRegister("_mover", "long", "int;wparam;lparam")
$pm_callback = DllCallbackGetPtr($m_callback)
$hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pm_callback, _WinAPI_GetModuleHandle(0))

While 1

Func OnAutoItExit()


Func _mover($nCode, $wparam, $lparam)
If $nCode<0 Then Return _WinAPI_CallNextHookEx($hook, $nCode, $wparam, $lparam)
ConsoleWrite("jk" & @CRLF)
Switch Number($wparam)
Local $pos = DllStructCreate("long;long", $lparam)
$x = DllStructGetData($pos, 1)
$y = DllStructGetData($pos, 2)
_GUIToolTip_TrackPosition($hTool, $x+25, $y+15)
_GUIToolTip_UpdateTipText($hTool, 0, 0, "Pos: " & $x & " x " & $y)

Return _WinAPI_CallNextHookEx($hook, $nCode, $wparam, $lparam)

from help file.

; Create callback function
Local $handle = DllCallbackRegister("_EnumWindowsProc", "int", "hwnd;lparam")

; Call EnumWindows
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($handle), "lparam", 10)

; Delete callback function

; Callback Procedure
Func _EnumWindowsProc($hWnd, $lParam)
If WinGetTitle($hWnd) <> "" And BitAND(WinGetState($hWnd), 2) Then
Local $res = MsgBox(1, WinGetTitle($hWnd), "$hWnd=" & $hWnd & @CRLF & "lParam=" & $lParam & @CRLF & "$hWnd(type)=" & VarGetType($hWnd))
If $res = 2 Then Return 0 ; Cancel clicked, return 0 to stop enumeration
Return 1 ; Return 1 to continue enumeration
EndFunc ;==>_EnumWindowsProc


Edited by Danyfirex
Link to comment
Share on other sites

Sorry but I have not figured yet how the function works : Can someone explain me the concept?

When you call DllCallbackRegister then AutoIt performs "just in time" compilation (aka JIT) and gives you back the handle that you can use to get pointer to compiled code.

Other functions that make use of the callback functions will ask you for that pointer and will redirect execution to your callback code as defined by their documentation.

For example see documentation for EnumWindows function (Danyfirex's second and help file example) .

Edited by trancexx




Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...