BinaryBrother Posted March 18, 2009 Share Posted March 18, 2009 (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... expandcollapse popup#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 March 18, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
ProgAndy Posted March 18, 2009 Share Posted March 18, 2009 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: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 18, 2009 Author Share Posted March 18, 2009 So, in theory... It isn't supposed to open more than 1 message box? Or is that normal for that sort of operation? SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
ProgAndy Posted March 18, 2009 Share Posted March 18, 2009 (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 March 18, 2009 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 Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 18, 2009 Author Share Posted March 18, 2009 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 interruptedAhh, I get it now... Thanks for the insight ProgAndy, I appreciate it... SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now