AustrianOak Posted July 27, 2008 Share Posted July 27, 2008 (edited) I am getting an error that says: "DllCallbackFree($TimerProcHandle)" "DllCallbackFree(^ ERROR Error: Variable used without being declared. It appears when I try to run (for testing purposes) my script again when I set it to single instance. Here is the UDF I believe that was given to me by rasim (I'm hoping you can help with this since it's your UDF) UDF: expandcollapse popup#include-once #include <WindowsConstants.au3> #include <ToolTipConstants.au3> #include <FontConstants.au3> #include <Constants.au3> Global Const $CW_USEDEFAULT = 0x80000000 Global Const $TOOLTIPS_CLASSA = "tooltips_class32" Global Const $TTDT_AUTOPOP = 2 Global Const $SHRT_MAX = 32767 Global $hToolTip = False Global $TOOLINFO Global $LastHwnd Global $aControl[1] = [0] Global $aText[1] = [0] Global $aTitle[1] = [0] Global $aIcon[1] = [0] Global $aTextColor[1] = [0] Global $aBkColor[1] = [0] Global $aFontSize[1] = [0] Global $aFontWeight[1] = [0] Global $aFontAtrrib[1] = [0] Global $aFont[1] = [0] Global $TimerProcHandle = DllCallbackRegister("_TimerProc", "none", "hwnd;int;int;dword") Global $TimerCall = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, "int", 0, "int", 100, _ "ptr", DllCallbackGetPtr($TimerProcHandle)) ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetText ; Description.....: Sets the tooltip text associated with a control ; Syntax..........: _ToolTip_SetText($hControl, $sText, $sTitle = "", $sIcon = 0) ; Parameter(s)....: $hControl - The control identifier or handle ; $sText - Tip text that will be displayed when the mouse is hovered over the control ; $sTitle - [optional] The title for the tooltip Requires IE5+ ; $sIcon - [optional] The icon for the tooltip ; +0 = No icon, 1 = Info icon, 2 = Warning icon, 3 = Error icon 7 = Question icon Requires IE5+ ; Return value(s).: Success - None ; Failure - Sets @error to 1 and returns 0 if $sText param contains a empty string ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetText($hControl, $sText, $sTitle = "", $sIcon = 0) If $sText = "" Then Return SetError(1, 0, 0) If $hToolTip = False Then $hToolTip = _ToolTip_Create() If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl) Local $iElement = _FindControl($hControl) $aTitle[$iElement] = $sTitle $aIcon[$iElement] = $sIcon Local $tBuffer = DllStructCreate("char[256]") DllStructSetData($tBuffer, 1, $sText) DllStructSetData($TOOLINFO, "uId", $hControl) DllStructSetData($TOOLINFO, "lpszText", DllStructGetPtr($tBuffer)) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_ADDTOOL, "int", 0, _ "ptr", DllStructGetPtr($TOOLINFO)) EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetTextColor ; Description.....: Sets the color of text in the tooltip ; Syntax..........: _ToolTip_SetTextColor($hControl, $sColor) ; Parameter(s)....: $hControl - The control identifier or handle ; $sColor - The color expression in HEX value ; Return value(s).: Success - None ; Failure - Sets @error to 1 and returns 0 if $sColor param contains a empty string ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetTextColor($hControl, $sColor) If Not $sColor Then Return SetError(1, 0, 0) If $hToolTip = False Then $hToolTip = _ToolTip_Create() If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl) Local $iElement = _FindControl($hControl) $aTextColor[$iElement] = _RGB2BGR($sColor) EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetBkColor ; Description.....: Sets the background color of the tooltip window ; Syntax..........: _ToolTip_SetBkColor($hControl, $sColor) ; Parameter(s)....: $hControl - The control identifier or handle ; $sColor - The color expression in HEX value ; Return value(s).: Success - None ; Failure - Sets @error to 1 and returns 0 if $sColor param contains a empty string ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetBkColor($hControl, $sColor) If Not $sColor Then Return SetError(1, 0, 0) If $hToolTip = False Then $hToolTip = _ToolTip_Create() If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl) Local $iElement = _FindControl($hControl) $aBkColor[$iElement] = _RGB2BGR($sColor) EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetFont ; Description.....: Sets the font size, weight, attributes and font name for a tooltip text ; Syntax..........: _ToolTip_SetFont($hControl, $sFontSize, $sFontWeight = 400, $sFontAtrribute = 0, $sFont = "") ; Parameter(s)....: $hControl - The control identifier or handle ; $sFontSize - Fontsize (default is 10) ; $sFontWeight - [optional] Font weight (default 400 = normal) ; $sFontAtrribute - [optional] To define italic:2 underlined:4 strike:8 char formats ; $sFont - [optional] The name of the font to use ; Return value(s).: Success - None ; Failure - Sets @error to 1 and returns 0 if $sFontSize param contains a empty or not numeric string ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetFont($hControl, $sFontSize, $sFontWeight = 400, $sFontAtrribute = 0, $sFont = "") If ($sFontSize = "") Or (IsNumber($sFontSize) = 0) Then Return SetError(1, 0, 0) If $hToolTip = False Then $hToolTip = _ToolTip_Create() If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl) Local $iElement = _FindControl($hControl) $aFontSize[$iElement] = $sFontSize $aFontWeight[$iElement] = $sFontWeight $aFontAtrrib[$iElement] = $sFontAtrribute $aFont[$iElement] = $sFont EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetShowTime ; Description.....: Sets time the tooltip should be displayed ; Syntax..........: _ToolTip_SetShowTime($sTime) ; Parameter(s)....: $hControl - The control identifier or handle ; $sTime - Estimate of the time (in miliseconds) the tooltip should be displayed ; Return value(s).: Success - None ; Failure - Sets @error to 1 and returns 0 if $sTime param contains a empty or not numeric string ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetShowTime($sTime) If ($sTime = "") Or (IsNumber($sTime) = 0) Then Return SetError(1, 0, 0) If $sTime > $SHRT_MAX Then $sTime = $SHRT_MAX If $hToolTip = False Then $hToolTip = _ToolTip_Create() DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETDELAYTIME, "dword", $TTDT_AUTOPOP, _ "int", $sTime) EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_SetBaloonStyle ; Description.....: Sets tooltips as balloon tip Requires IE5+ ; Syntax..........: _ToolTip_SetBaloonStyle() ; Parameter(s)....: None ; Return value(s).: None ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Tested on Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_SetBaloonStyle() If $hToolTip = False Then $hToolTip = _ToolTip_Create() Local $aRet = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hToolTip, "int", $GWL_STYLE) DllCall("user32.dll", "int", "SetWindowLong", "hwnd", $hToolTip, "int", $GWL_STYLE, "int", BitOR($aRet[0], $TTS_BALLOON)) EndFunc ; #FUNCTION# ============================================================= ; Name............: _ToolTip_Create ; Description.....: Create a tooltip window ; Syntax..........: _ToolTip_Create() ; Parameter(s)....: None ; Return value(s).: The handle of tooltip window ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Internal use only ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _ToolTip_Create() $hToolTip = DllCall("user32.dll", "hwnd", "CreateWindowEx", "int", $WS_EX_TOPMOST, "str", $TOOLTIPS_CLASSA, _ "str", 0, "int", BitOR($WS_POPUP, $TTS_ALWAYSTIP), "int", $CW_USEDEFAULT, _ "int", $CW_USEDEFAULT, "int", $CW_USEDEFAULT, "int", $CW_USEDEFAULT, "hwnd", 0, "hwnd", 0, _ "hwnd", 0, "ptr", 0) $TOOLINFO = DllStructCreate("int cbSize;int uFlags;hwnd hWnd;int uId;int rect[4];hwnd hinst;" & _ "ptr lpszText;int lParam;int lpReserved") DllStructSetData($TOOLINFO, "cbSize", DllStructGetSize($TOOLINFO)) DllStructSetData($TOOLINFO, "uFlags", BitOR($TTF_IDISHWND, $TTF_SUBCLASS)) DllStructSetData($TOOLINFO, "hinst", 0) DllStructSetData($TOOLINFO, "lParam", 0) DllStructSetData($TOOLINFO, "lpReserved", 0) Return $hToolTip[0] EndFunc ; #FUNCTION# ============================================================= ; Name............: _FindControl ; Description.....: Finds the control handle in the array which contains a controls handles ; Syntax..........: _FindControl($hControl) ; Parameter(s)....: $hControl - Handle to the control ; Return value(s).: Last array element number ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Internal use only ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _FindControl($hControl) Local $i If $aControl[0] = 0 Then Return _RedimArray($hControl) For $i = 1 To $aControl[0] If $hControl = $aControl[$i] Then Return $i Next Return _RedimArray($hControl) EndFunc ; #FUNCTION# ============================================================= ; Name............: _RedimArray ; Description.....: Redims arrays with parameters and sets default parameters ; Syntax..........: _RedimArray($hControl) ; Parameter(s)....: $hControl - Handle to the control ; Return value(s).: Last element number from the array contains a controls handles ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Internal use only ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _RedimArray($hControl) $aControl[0] += 1 ReDim $aControl[$aControl[0] + 1] $aControl[$aControl[0]] = $hControl $aTitle[0] += 1 ReDim $aTitle[$aTitle[0] + 1] $aTitle[$aTitle[0]] = "" $aIcon[0] += 1 ReDim $aIcon[$aIcon[0] + 1] $aIcon[$aIcon[0]] = 0 $aTextColor[0] += 1 ReDim $aTextColor[$aTextColor[0] + 1] $aTextColor[$aTextColor[0]] = 0x000000 $aBkColor[0] += 1 ReDim $aBkColor[$aBkColor[0] + 1] $aBkColor[$aBkColor[0]] = _RGB2BGR(0xFFFFE1) $aFontSize[0] += 1 ReDim $aFontSize[$aFontSize[0] + 1] $aFontSize[$aFontSize[0]] = 10 $aFontWeight[0] += 1 ReDim $aFontWeight[$aFontWeight[0] + 1] $aFontWeight[$aFontWeight[0]] = 400 $aFontAtrrib[0] += 1 ReDim $aFontAtrrib[$aFontAtrrib[0] + 1] $aFontAtrrib[$aFontAtrrib[0]] = 0 $aFont[0] += 1 ReDim $aFont[$aFont[0] + 1] $aFont[$aFont[0]] = "Tahoma" Return $aControl[0] EndFunc ; #FUNCTION# ============================================================= ; Name............: _CreateFont ; Description.....: Creates a logical font with the specified characteristics ; Syntax..........: _CreateFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) ; Parameter(s)....: $hWnd - The window handle ; $sFontSize - Fontsize (default is 10) ; $sFontWeight - Font weight (default 400 = normal) ; $sFontAtrribute - To define italic:2 underlined:4 strike:8 char formats ; $sFont - The name of the font to use ; Return value(s).: None ; Requirement(s)..: AutoIt 3.2.12.0 ; Note(s).........: Internal use only ; Author(s).......: R.Gilman (a.k.a. rasim) ; ======================================================================== Func _CreateFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc ; #FUNCTION# ============================================================= ; Name............: RGB2BGR ; Description.....: Convert a RGB color mode to a BGR color mode ; Syntax..........: RGB2BGR($sColor) ; Parameter(s)....: $sColor - The color in HEX value ; Return value(s).: Converted color in HEX value ; Requirement(s)..: ; Note(s).........: ; Author(s).......: Siao ; ======================================================================== Func _RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc ;==>_RGB2BGR() Func _TimerProc($hWnd, $Msg, $IdTimer, $dwTime) Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "int", MouseGetPos(0), "int", MouseGetPos(1)) $iRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iRet[0]) If ($iRet[0] = 0) Or ($iRet[0] = 350) Then Return False Local $hControl = $iRet[0] If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl) If $hControl = $LastHwnd Then Return False For $i = 1 To $aControl[0] If $hControl = $aControl[$i] Then DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTITLE, "int", $aIcon[$i], "str", $aTitle[$i]) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTIPTEXTCOLOR, "int", $aTextColor[$i], "int", 0) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTIPBKCOLOR, "int", $aBkColor[$i], "int", 0) _CreateFont($hToolTip, $aFontSize[$i], $aFontWeight[$i], $aFontAtrrib[$i], $aFont[$i]) EndIf Next $LastHwnd = $hControl EndFunc Func OnAutoitExit() DllCallbackFree($TimerProcHandle) DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $TimerCall) $hToolTip = 0 $TOOLINFO = 0 DllCall("User32.dll", "int", "DestroyWindow", "hwnd", $hToolTip) EndFunc ;==>OnAutoitExit In the last function is where I believe the error is occuring. Please help. Edited July 28, 2008 by SmOke_N Put in AutoIt code tags so it had a scroll option Link to comment Share on other sites More sharing options...
Andreik Posted July 27, 2008 Share Posted July 27, 2008 (edited) I am getting an error that says:"DllCallbackFree($TimerProcHandle)""DllCallbackFree(^ ERRORError: Variable used without being declared.It appears when I try to run (for testing purposes) my script again when I set it to single instance.Here is the UDF I believe that was given to me by rasim (I'm hoping you can help with this since it's your UDF)UDF:<snip>I don't see in your code where is defined function DllCallbackFree().Try #include <DllCallBack.au3> Edited July 28, 2008 by SmOke_N When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rasim Posted July 27, 2008 Share Posted July 27, 2008 nowagainWorks fine for me. What the AutoIt version you are using? Link to comment Share on other sites More sharing options...
BrettF Posted July 27, 2008 Share Posted July 27, 2008 Guys... Have we not heard of the codebox? [ code][ /code] (without the space at the start...) It makes the page SO long its not funny.... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
AustrianOak Posted July 27, 2008 Author Share Posted July 27, 2008 nowagainWorks fine for me. What the AutoIt version you are using?I'm using 3.2.11.8 beta Link to comment Share on other sites More sharing options...
rasim Posted July 28, 2008 Share Posted July 28, 2008 nowagainI'm using 3.2.11.8 betaI don`t have a beta version and don`t testing this UDF on a beta version. Link to comment Share on other sites More sharing options...
AustrianOak Posted July 28, 2008 Author Share Posted July 28, 2008 Well can you at least tell me what function to take out and how to fix this? Link to comment Share on other sites More sharing options...
martin Posted July 28, 2008 Share Posted July 28, 2008 Well can you at least tell me what function to take out and how to fix this?In the script where you get this error you must have a line somewhere which says $TimerProcHandle = .... if it says Global $TimerProcHandle = .... then remove the initial Global. Then, at the start of your script, where it will always get executed, write Global $TimerProcHandle = -1 Then change the line where you have the problem to If $TimerProcHandle <> -1 then DllCallbackFree($TimerProcHandle) endif Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
rover Posted July 28, 2008 Share Posted July 28, 2008 (edited) the problem is with your OnAutoitExit() function in the UDF. when you run a a second instance of the script, the _Singleton function (I assume that's what your using) will exit via OnAutoitExit() and without a valid callback handle you get the error message. use a globally declared flag variable at the top of your script in the OnAutoitExit() function that bypasses the callback when exiting. Edit: typo, clarity set the $flag variable to 1 if single instance of script, else default to 0 then when script exits it will bypass the callback closing dllcalls. Global $flag = 0 ; default value, set to 1 if script is single instance Func OnAutoitExit() If Not $flag Then Exit Beep(1000,5) DllCallbackFree($TimerProcHandle) DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $TimerCall) $hToolTip = 0 $TOOLINFO = 0 DllCall("User32.dll", "int", "DestroyWindow", "hwnd", $hToolTip) EndFunc ;==>OnAutoitExit Edited July 28, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
AustrianOak Posted July 28, 2008 Author Share Posted July 28, 2008 @rover: it says variable used without being declared when i try to run the script again? Link to comment Share on other sites More sharing options...
rasim Posted July 29, 2008 Share Posted July 29, 2008 nowagainAs say martin change the problem line to:If $TimerProcHandle <> 0 then DllCallbackFree($TimerProcHandle) EndIfBecause DllCallbackRegister() func. returns 0 if error occurs.P.S.In latest stable AutoIt version, this UDF works fine. Link to comment Share on other sites More sharing options...
AustrianOak Posted July 29, 2008 Author Share Posted July 29, 2008 Will try it but can't upgrade to lastest as my script is too big right now. Link to comment Share on other sites More sharing options...
AustrianOak Posted July 29, 2008 Author Share Posted July 29, 2008 It causes my script to crash. (It never even loads up and then a box pops up saying Autoit3.exe has encountered a problem and needs to close) Link to comment Share on other sites More sharing options...
AustrianOak Posted July 29, 2008 Author Share Posted July 29, 2008 (edited) the script is still crashing when i changed it from -1 to 0 Edit: I believe I wasted my time on this now remembering that there are UDFs for this already. Thanks, topic closed. Edited July 29, 2008 by nowagain 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