Sign in to follow this  
Followers 0
BinaryBrother

DLLCallbackRegister() [RESOLVED]

5 posts in this topic

#1 ·  Posted (edited)

I was messing with DLLCallbackRegister() with the following code... and was getting some MASSIVE memory eating... lol. So I threw a message box in there for debugging, and it opened a MsgBox like a couple HUNDRED times... ROFL... How did it do that? I thought MsgBox paused the script... Is that like MultiThreading? I could really use this in a script I'm building, but I need to know a little more about how exactly it works first... :P

#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_TrackActivate($hTool)
_GUIToolTip_SetTitle($hTool, "CPU Info:", 1)

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

While 1
    sleep(1000)
WEnd


_WinAPI_UnhookWindowsHookEx($hook)
DllCallbackFree($m_callback)
_WinAPI_DestroyWindow($hTool)

Exit

Func _move($nCode, $wparam, $lparam)
    Switch $wparam
        Case $WM_MOUSEMOVE
            Local $pos = DllStructCreate("long;long", $lparam)
            ;MsgBox(0,"","test")
            $x = DllStructGetData($pos, 1)
            $y = DllStructGetData($pos, 2)
            _GUIToolTip_TrackPosition($hTool, $x+25, $y+15)
            _GUIToolTip_UpdateTipText($hTool, 0, 0, "Pos: " & $x & " x " & $y)
    EndSwitch
   
    Return _WinAPI_CallNextHookEx($hook, $nCode, $wparam, $lparam)
EndFunc

I'm thinking that would be better in a While loop anyway, instead of a Function call I don't fully understand... lol

Edited by BinaryBrother

Share this post


Link to post
Share on other sites



Insert this line as the first on in _move. Possibly, this is the memory leak:

If $nCode<0 Then Return _WinAPI_CallNextHookEx($hook, $nCode, $wparam, $lparam)

Also, i had to specify a module handle in SetWindowsHookEx. And for me, the memory usage stays constant:

#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_TrackActivate($hTool)
_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
    sleep(1000)
WEnd

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hook)
    DllCallbackFree($m_callback)
    _WinAPI_DestroyWindow($hTool)
EndFunc

Exit

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

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

So, in theory... It isn't supposed to open more than 1 message box? Or is that normal for that sort of operation?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is normal for this operation. The callback interrupts the executing code. Now the callback executes. If another or the same callback is called and the old hasn't finished, it will interrupt the old callback, too and execute itself. This continues every time a callback is executed. If you have MsgBoxes in the callback, one will be opened.

-> so you can't use it as multithreading, since everything but the most recent callback is interrupted

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

This is normal for this operation. The callback interrupts the executing code. Now the callback executes. If another or the same callback is called and the old hasn't finished, it will interrupt the old callback, too and execute itself. This continues every time a callback is executed. If you have MsgBoxes in the callback, one will be opened.

-> so you can't use it as multithreading, since everything but the most recent callback is interrupted

Ahh, I get it now... Thanks for the insight ProgAndy, I appreciate it... :P

Share this post


Link to post
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
Sign in to follow this  
Followers 0