jfisher Posted September 3, 2007 Posted September 3, 2007 I have an array that is created dynamically with data from a text file. How can I completely wipe it clean and start with a clean slate for the next time it needs to be set? btw, I don't know the size or any information about it besides the name.
flip209 Posted September 3, 2007 Posted September 3, 2007 could you post some code. but this could work $array = "" " I haven't failed. I've just found 10,000 ways that won't work." Thomas Edison "You cannot help men permanently by doing for them what they could and should do for themselves." Abraham Lincoln
jfisher Posted September 3, 2007 Author Posted September 3, 2007 Global $ContextMenu = GUICtrlCreateContextMenu() Global $varMenuList = IniReadSection($sIniLocation, "ValidationPositives") $varMenuLength = $varMenuList[0][0] Global $varMenuArray[$varMenuLength+1] $varMenuArray[0] = $varMenuList[0][0] For $i = 1 to ubound($varMenuList) - 1 $varMenuID = GUICtrlCreateMenuItem ($varMenuList[$i][0], $ContextMenu) $varMenuArray[$i] = $varMenuID GUICtrlSetOnEvent($varMenuID,"testfunc") Next ShowMenu($hWnd_ui, $ContextMenu)oÝ÷ Øk¢^u«¢+Ø$$$$$$ÀÌØíÙÉ5¹ÕÉÉäôÅÕ½ÐìÅÕ½Ðì($$$$$$ÀÌØíÙÉ5¹Õ1¥ÍÐôÅÕ½ÐìÅսРin front of it to clear out before use again, but get: E:\AdvisorGUI\AutoIt\Include\Subclass.au3 (69) : ==> Subscript used with non-Array variable.: $varMenuLength = $varMenuList[0][0] $varMenuLength = $varMenuList^ ERROR
jfisher Posted September 3, 2007 Author Posted September 3, 2007 even if I redim $varMenuLength as Global inside, I still get E:\AdvisorGUI\AutoIt\Include\Subclass.au3 (69) : ==> Subscript used with non-Array variable.: Global $varMenuLength = $varMenuList[0][0] Global $varMenuLength = $varMenuList^ ERROR
MrCreatoR Posted September 3, 2007 Posted September 3, 2007 ReDim $Array[1][1] Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted September 4, 2007 Moderators Posted September 4, 2007 (edited) ReDim $Array[1][1]oÝ÷ Øò¢ìÛhuë-®æ«¬¯j[±»²Ø¥f¤z+Zªëk,"¶.¶¯x-¢Z(¦Øk¢è!z÷«Éé^éíÊ¢é]¶¼¬¢g)à)¶¬jëh×6Dim $aArray[3][3] = [[ 1, 2, 3],[ 4, 5, 6]] MsgBox(0,"=1",$aArray[0][0]) ReDimDestroy($aArray) MsgBox(0, "=1", $aArray[0][0]) Func ReDimDestroy(ByRef $avArray) ;Only doing up to 3 indexes as an example Local $nUCount = 0 For $iCC = 1 To 3 UBound($avArray, $iCC) If @error Then ExitLoop $nUCount = $iCC Next If $nUCount = 0 Then Return SetError(1, 0, "") Switch $nUCount Case 1 Local $aArray[1] $avArray = $aArray Case 2 Local $aArray[1][1] $avArray = $aArray Case 3 Local $aArray[1][1][1] $avArray = $aArray EndSwitch Return 1 EndFunc Edit: You could set an optional parameter for the redim values along with stringsplit(), this is just a quick example. Edit2: had to fix the error with forum edit output. Edited September 4, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Moderators SmOke_N Posted September 4, 2007 Moderators Posted September 4, 2007 (edited) Here's a bloated example quick and dirty of what I'm talking about above.expandcollapse popup#include <array.au3> Dim $aArray[3][3] = [[ 1, 2, 3],[ 4, 5, 6]] MsgBox(0,"=1",$aArray[0][0]) ReDimDestroy($aArray) MsgBox(0, "=1", $aArray[0][0]) Func ReDimDestroy(ByRef $avArray, $nDimensions = "1,1,1") ;Only doing up to 3 indexes as an example If $nDimensions = "" Or $nDimensions = -1 Or $nDimensions = Default Then $nDimensions = "1,1,1" Local $nUCount = 0, $aSRE = StringRegExp($nDimensions, "(\d+)", 3) Local $nUSRE = UBound($aSRE) - 1 If IsArray($aSRE) = 0 Then Local $aSRE[3] = [1,1,1] ElseIf $nUSRE = 0 Then ReDim $aSRE[3] $aSRE[1] = 1 $aSRE[2] = 1 ElseIf $nUSRE = 1 Then ReDim $aSRE[3] $aSRE[2] = 1 EndIf For $iCC = 1 To 3 UBound($avArray, $iCC) If @error Then ExitLoop $nUCount = $iCC Next If $nUCount = 0 Then Return SetError(1, 0, "") Switch $nUCount Case 1 Local $aArray[$aSRE[0]] $avArray = $aArray Case 2 Local $aArray[$aSRE[0]][$aSRE[1]] $avArray = $aArray Case 3 Local $aArray[$aSRE[0]][$aSRE[1]][$aSRE[2]] $avArray = $aArray EndSwitch Return 1 EndFunc Edited September 4, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MrCreatoR Posted September 4, 2007 Posted September 4, 2007 Our redim automatically preserves values, so your [1][1] would have the same value it always had.It's just for zero-based element? So why not just set it to empty value? Dim $aArray[3][3] = [[ 1, 2, 3],[ 4, 5, 6]] MsgBox(0,"=1",$aArray[0][0]) ReDim $aArray[1][1] $aArray[0][0] = "" MsgBox(0, "Not = 1", $aArray[0][0]) And i have checked my results with _ArrayDisplay(), witch is not showing any values (for my first example). Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted September 4, 2007 Moderators Posted September 4, 2007 It's just for zero-based element? So why not just set it to empty value? Dim $aArray[3][3] = [[ 1, 2, 3],[ 4, 5, 6]] MsgBox(0,"=1",$aArray[0][0]) ReDim $aArray[1][1] $aArray[0][0] = "" MsgBox(0, "Not = 1", $aArray[0][0]) And i have checked my results with _ArrayDisplay(), witch is not showing any values (for my first example).You missed the point of redim then. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
SkinnyWhiteGuy Posted September 4, 2007 Posted September 4, 2007 Dim $Test[3] $Test[0] = "a" $Test[1] = 3 $Test[2] = @ComputerName For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next Dim $Test[3] For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next $Test[0] = "b" $Test[1] = 9 $Test[2] = @OSVersion For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next Whenever I need an array emptied, I just Dim it again, or Local/Global it, that usually wipes it clean. Since you said you dynamically build it when reading in the file, just Dim $array[1] should wipe it and leave it with 1 element. If you need it the same size as before, just Dim $array[uBound($array)].
Moderators SmOke_N Posted September 4, 2007 Moderators Posted September 4, 2007 (edited) Dim $Test[3] $Test[0] = "a" $Test[1] = 3 $Test[2] = @ComputerName For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next Dim $Test[3] For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next $Test[0] = "b" $Test[1] = 9 $Test[2] = @OSVersion For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next Whenever I need an array emptied, I just Dim it again, or Local/Global it, that usually wipes it clean. Since you said you dynamically build it when reading in the file, just Dim $array[1] should wipe it and leave it with 1 element. If you need it the same size as before, just Dim $array[uBound($array)].It's kind of hard to do that in a function... try it and see what your results are. Edit: I should say when passing it to a function. Edited September 4, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
SkinnyWhiteGuy Posted September 4, 2007 Posted September 4, 2007 expandcollapse popupDim $Test[3] $Test[0] = "a" $Test[1] = 3 $Test[2] = @ComputerName For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next _ClearArray1($Test) For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next $Test[0] = "b" $Test[1] = 9 $Test[2] = @OSVersion For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next $Test = _ClearArray2($Test) For $i = 0 To 2 ConsoleWrite($i & ": " & $Test[$i] & @CRLF) Next Func _ClearArray1(ByRef $Array) Dim $Array[UBound($Array)] EndFunc Func _ClearArray2($Array) Dim $Array[UBound($Array)] Return $Array EndFunc
jfisher Posted September 4, 2007 Author Posted September 4, 2007 Whenever I need an array emptied, I just Dim it again, or Local/Global it, that usually wipes it clean. Since you said you dynamically build it when reading in the file, just Dim $array[1] should wipe it and leave it with 1 element. If you need it the same size as before, just Dim $array[uBound($array)]. See this is what I took away when I read the help. So therefore if this is the case, then th array is started completely from a clean slate when I Global $array = whatever[] again. If that's working as expected, then I fear the problem may be somewhere else. I'm about to giveup on this thing, but really can't so here's the trouble code in full. I have included the #include file at the top of it as a region so I dont have to attach a bunch of files. This is what I know: When I call Showmenu I am consolewriting the menu's handle. The first time, the menu shows up and theres a handle set, the second and subsequent times there is no handle for the menu itself. Like I said I thought it was old array values getting in the way, but they should be cleared out when its Global'd, unless thats just wrong. Please look over it and see what you think. Thanks for the help guys. The trouble spot is highlighted in comments. Just run and right click in the edit control. expandcollapse popup;this region is just the dll callback include file, included so I dont have to attach a file for those that don't have it. #region DLLCallBackInclude File ; Adjustable values Global Const $gi_DllCallBack_uiMsg = 0x7FFF ; WM_USER + 0x7BFF Global Const $gi_DllCallBack_MaxStubs = 64 ; Constants for $nOptions Global Const $_DllCallBack_StdCall = 0 Global Const $_DllCallBack_Cdecl = 1 Global Const $_DllCallBack_Sync = 2 Global Const $_DllCallBack_Subclass = 4 Global Const $_DllCallBack_Struct = 8 Global Const $_DllCallBack_Debug = 1024 ; Internaly used Global Const $gs_DllCallBack_typedef_CriticalSection = "PTR DebugInfo;LONG LockCount;LONG RecursionCount;PTR OwningThread;PTR LockSemaphore;DWORD SpinCount" Global $gp_DllCallBack_SendMessage = 0 Global $gh_DllCallBack_hUser32 = 0 Global $gi_DllCallBack_StubCount = 0 Global $gp_DllCallBack_EnterCriticalSection = 0 Global $gp_DllCallBack_LeaveCriticalSection = 0 Global $gp_DllCallBack_CallWindowProc = 0 Global $gh_DllCallBack_hWnd = GUICreate("au3_Callback") Global $gf_DllCallBack_fMsgRegistred = GUIRegisterMsg($gi_DllCallBack_uiMsg, "__DllCallBack_MsgHandler") Global $ga_DllCallBack_sParameters[$gi_DllCallBack_MaxStubs + 1] Global $ga_DllCallBack_nParameters[$gi_DllCallBack_MaxStubs + 1] Global $ga_DllCallBack_sFunctions[$gi_DllCallBack_MaxStubs + 1] Global $ga_DllCallBack_hGlobals[$gi_DllCallBack_MaxStubs + 1] Global $ga_DllCallBack_vCriticalSections[$gi_DllCallBack_MaxStubs + 1] Global $ga_DllCallBack_nOptions[$gi_DllCallBack_MaxStubs + 1] ;=============================================================================== ; ; Function Name: _DllCallBack ; Description: Registers a callback function and creates a stub which handles incoming calls. ; Parameter(s): $sFunction - Name of callback function ; $sParameters - DllStruct like parameter definition (only 32 and 64bit datatypes supported) ; $nOptions, Optional - Can be one or more (add them together) of the folowing constants: ; $_DllCallBack_StdCall (0) - Use 'stdcall' calling method (Default) ; $_DllCallBack_Cdecl (1) - Use 'cdecl' calling method ; $_DllCallBack_Sync (2) - Enable Critical Section (see Remarks) ; $_DllCallBack_Subclass (4) - Enable Subclassing (see Remarks) ; $_DllCallBack_Struct (8) - Pass the struct to the handler function (see Remarks) ; $_DllCallBack_Debug (1024) - Enable breakpoint (requires a JIT debugger) ; Requirement(s): ; Return Value(s): Pointer to created stub or NULL on error ; @error Value(s): 1 = Error allocating memory ; 2 = Error Loading User32.dll or Kernel32.dll ; 3 = Failed to get the address of SendMessage, EnterCriticalSection, LeaveCriticalSection or CallWindowProc ; 4 = Too many callbacks ; 5 = GUIRegisterMsg() Failed ; 6 = $sParameters Fromat wrong ; 7 = Error calling InitializeCriticalSection ; ; Author(s): Florian Fida ; Remarks: The number of coexistent callback stubs is limited to 64. ; Windows message WM_USER + 0x7BFF is used by this function. ; ; If Subclassing is enabled the callback function must not call 'CallWindowProc' itself. ; If the Function processes the message it should return NULL if not is has to return a Pointer ; to the previous 'WindowProc' Function. ; ; Critical sections allow better synchronisation, if a multithreaded library calls ; the callback function, enable this option. ; ; Passing the struct requires the callback function to accept one parameter which is the ; Struct defined in $sParameters. This allows the modification of the stack. ; ;=============================================================================== ; Func _DllCallBack($sFunction, $sParameters = "", Const $nOptions = 0) Local $pSendMessage, $hGlobal, $hUser32, $vStub, $i, $vCriticalSection, $pCallWindowProc Local $nParameters, $vParameters, $wParam = -1, $nParameters_struct = -1, $hKernel32 Local $sStub, $dwStubSize If BitAND($_DllCallBack_Debug, $nOptions) Then $sStub = "90909090CC" ; INT3 If Not $gf_DllCallBack_fMsgRegistred Then Return SetError(5, 0, 0) If $sParameters = "" Or $sParameters = Default Then $nParameters = 0 Else $vParameters = DllStructCreate($sParameters) If @error Then Return SetError(6, 0, 0) $nParameters = DllStructGetSize($vParameters) / 4 If $nParameters <> Int($nParameters) Or @error Then Return SetError(6, 0, 0) For $i = 1 To 256 DllStructGetData($vParameters, $i) If @error Then $nParameters_struct = $i - 1 ExitLoop EndIf Next If $nParameters_struct < 0 Then SetError(6, 0, 0) EndIf For $i = 0 To $gi_DllCallBack_MaxStubs If Not $ga_DllCallBack_hGlobals[$i] Then $wParam = $i ExitLoop EndIf Next If $wParam = -1 Then Return SetError(4, 0, 0) If $gh_DllCallBack_hUser32 = 0 Then $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll") If @error Then Return SetError(2, 0, 0) If $hUser32[0] = 0 Then Return SetError(2, 0, 0) $gh_DllCallBack_hUser32 = $hUser32[0] $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessage") If @error Then Return SetError(3, 0, 0) If $pSendMessage[0] = 0 Then If @Unicode Then $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessageW") If @error Then Return SetError(3, 0, 0) Else $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessageA") If @error Then Return SetError(3, 0, 0) EndIf EndIf If $pSendMessage[0] = 0 Then Return SetError(3, 0, 0) $gp_DllCallBack_SendMessage = $pSendMessage[0] $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProc") If @error Then Return SetError(3, 0, 0) If $pCallWindowProc[0] = 0 Then If @Unicode Then $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProcW") If @error Then Return SetError(3, 0, 0) Else $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProcA") If @error Then Return SetError(3, 0, 0) EndIf EndIf If $pCallWindowProc[0] = 0 Then Return SetError(3, 0, 0) $gp_DllCallBack_CallWindowProc = $pCallWindowProc[0] EndIf If Not BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section disabled $vCriticalSection = -1 Else ; Critical section enabled If $gp_DllCallBack_EnterCriticalSection = 0 Or $gp_DllCallBack_LeaveCriticalSection = 0 Then ; we assume kernel32.dll is allways loaded $hKernel32 = DllCall("kernel32.dll", "ptr", "GetModuleHandle", "str", "kernel32.dll") If @error Then Return SetError(2, 0, 0) If $hKernel32[0] = 0 Then Return SetError(2, 0, 0) $gp_DllCallBack_EnterCriticalSection = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32[0], "str", "EnterCriticalSection") If @error Then Return SetError(3, 0, 0) $gp_DllCallBack_EnterCriticalSection = $gp_DllCallBack_EnterCriticalSection[0] If $gp_DllCallBack_EnterCriticalSection = 0 Then Return SetError(3, 0, 0) $gp_DllCallBack_LeaveCriticalSection = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32[0], "str", "LeaveCriticalSection") If @error Then Return SetError(3, 0, 0) $gp_DllCallBack_LeaveCriticalSection = $gp_DllCallBack_LeaveCriticalSection[0] If $gp_DllCallBack_LeaveCriticalSection = 0 Then Return SetError(3, 0, 0) EndIf $vCriticalSection = DllStructCreate($gs_DllCallBack_typedef_CriticalSection) DllCall("kernel32.dll", "none", "InitializeCriticalSection", "ptr", DllStructGetPtr($vCriticalSection)) If @error Then Return SetError(7, 0, 0) EndIf If @error Then Return SetError(7, 0, 0) #cs Options: Critical section, Breakpoint, stdcall - 2 parameters $ ==> > CC INT3 ; Breakpoint (for debugging only) $+1 > 68 30859B00 PUSH 9B8530 ; Push LPCRITICAL_SECTION $+6 > B8 0510917C MOV EAX,ntdll.RtlEnterCriticalSection ; Set address for EnterCriticalSection $+B > FFD0 CALL EAX ; Call EnterCriticalSection $+D > 8D4424 04 LEA EAX,DWORD PTR SS:[ESP+4] ; Load Pointer to parameters on stack to EAX $+11 > 50 PUSH EAX ; Push lParam - Stack Pointer $+12 > 68 00000000 PUSH 0 ; Push wParam - internal reference to au3 function $+17 > 68 FF7F0000 PUSH 7FFF ; Push uiMsg - internal identifier for callback $+1C > 68 26063000 PUSH 300626 ; Push hWnd - Autoit's Callback window $+21 > B8 AEE2D177 MOV EAX,USER32.SendMessageA ; Set address for SendMessage $+26 > FFD0 CALL EAX ; Call Sendmessage $+28 > 50 PUSH EAX ; Preserve Return value of Callback Function $+29 > 68 30859B00 PUSH 9B8530 ; Push LPCRITICAL_SECTION $+2E > B8 ED10917C MOV EAX,ntdll.RtlLeaveCriticalSection ; Set address for LeaveCriticalSection $+33 > FFD0 CALL EAX ; Call LeaveCriticalSection $+35 > 58 POP EAX ; Restore Return value of Callback Function $+36 > C2 0800 RETN 8 ; Adjust stack for stdcall and return Options: Default, stdcall - 2 parameters $ ==> > 8D4424 04 LEA EAX,DWORD PTR SS:[ESP+4] ; Load Pointer to parameters on stack to EAX $+4 > 50 PUSH EAX ; Push lParam - Stack Pointer $+5 > 68 00000000 PUSH 0 ; Push wParam - internal reference to au3 function $+A > 68 FF7F0000 PUSH 7FFF ; Push uiMsg - internal identifier for callback $+F > 68 C6041700 PUSH 1704C6 ; Push hWnd - Autoit's Callback window $+14 > B8 AEE2D177 MOV EAX,USER32.SendMessageA ; Set address for SendMessage $+19 > FFD0 CALL EAX ; Call Sendmessage $+1B > C2 0800 RETN 8 ; Adjust stack for stdcall and return nOptions: Subclassing, stdcall - 4 parameters $ ==> > 8D4424 04 LEA EAX,DWORD PTR SS:[ESP+4] ; Load Pointer to parameters on stack to EAX $+4 > 50 PUSH EAX ; Push lParam - Stack Pointer $+5 > 68 00000000 PUSH 0 ; Push wParam - internal reference to au3 function $+A > 68 FF7F0000 PUSH 7FFF ; Push uiMsg - internal identifier for callback $+F > 68 34063100 PUSH 310634 ; Push hWnd - Autoit's Callback window $+14 > B8 62B7D177 MOV EAX,USER32.SendMessageW ; Set address for SendMessage $+19 > FFD0 CALL EAX ; Call Sendmessage $+1B > 83F8 00 CMP EAX,0 ; Compare EAX and NULL $+1E > 74 1C JE SHORT <$+3C> ; If equal (EAX == NULL) jump down to $+3C (return) $+20 > 8B5424 10 MOV EDX,DWORD PTR SS:[ESP+10] ; Copy lParam from stack to EDX $+24 > 52 PUSH EDX ; Push lParam $+25 > 8B5424 10 MOV EDX,DWORD PTR SS:[ESP+10] ; Copy wParam from stack to EDX $+29 > 52 PUSH EDX ; Push wParam $+2A > 8B5424 10 MOV EDX,DWORD PTR SS:[ESP+10] ; Copy uiMsg from stack to EDX $+2E > 52 PUSH EDX ; Push uiMsg $+2F > 8B5424 10 MOV EDX,DWORD PTR SS:[ESP+10] ; Copy hWnd from stack to EDX $+33 > 52 PUSH EDX ; Push hWnd - Subclassed Window $+34 > 50 PUSH EAX ; Push lpPrevWndFunc (Returned by SendMessage/Callback Func) $+35 > B8 19C0D177 MOV EAX,USER32.CallWindowProcW ; Set address for CallWindowProc $+3A > FFD0 CALL EAX ; Call CallWindowProc $+3C > C2 1000 RETN 10 ; Adjust stack and return #ce ; Note: EAX ECX EDX can be freely modified If BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section $sStub &= "68" & __DllCallBack_Endian(DllStructGetPtr($vCriticalSection)) $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_EnterCriticalSection) $sStub &= "FFD0" ; call EnterCriticalSection EndIf $sStub &= "8D442404" ; load stack poiner into eax $sStub &= "50" ; push eax - lparam $sStub &= "68" & __DllCallBack_Endian($wParam, "uint") $sStub &= "68" & __DllCallBack_Endian($gi_DllCallBack_uiMsg, "uint") $sStub &= "68" & __DllCallBack_Endian($gh_DllCallBack_hWnd, "hwnd") $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_SendMessage) $sStub &= "FFD0" ; call SendMessage If BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section $sStub &= "50" ; push eax - to preserve return value of callback function $sStub &= "68" & __DllCallBack_Endian(DllStructGetPtr($vCriticalSection)) $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_LeaveCriticalSection) $sStub &= "FFD0" ; call LeaveCriticalSection $sStub &= "58" ; pop eax - Retstore return value EndIf If BitAND($_DllCallBack_Subclass, $nOptions) Then ; Subclassing $sStub &= "83F800"; cmp eax,0 $sStub &= "74" & "1C"; je 0x1c - if eax == 0 jump down 0x1c opcodes (to return) $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - lparam $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - wparam $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - msg $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - hwnd $sStub &= "50"; push eax - lpPrevWndFunc $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_CallWindowProc) ; Set eax to CallWindowProc $sStub &= "FFD0"; call eax EndIf If BitAND($_DllCallBack_Cdecl, $nOptions) Then $sStub &= "C3" ; return near 'cdecl' Else $sStub &= "C2" & __DllCallBack_Endian($nParameters * 4, "ushort", 2) ; Return near 'stdcall' EndIf $dwStubSize = StringLen($sStub) / 2 $hGlobal = DllCall("kernel32.dll", "ptr", "GlobalAlloc", "uint", 0, "dword", $dwStubSize) If @error Then Return SetError(1, 0, 0) If $hGlobal[0] = 0 Then Return SetError(1, 0, 0) $hGlobal = $hGlobal[0] $vStub = DllStructCreate("ubyte[" & $dwStubSize & "]", $hGlobal) DllStructSetData($vStub, 1, Binary("0x" & $sStub)) $gi_DllCallBack_StubCount += 1 $ga_DllCallBack_hGlobals[$wParam] = $hGlobal $ga_DllCallBack_sFunctions[$wParam] = $sFunction $ga_DllCallBack_sParameters[$wParam] = $sParameters $ga_DllCallBack_nParameters[$wParam] = $nParameters_struct $ga_DllCallBack_vCriticalSections[$wParam] = $vCriticalSection $ga_DllCallBack_nOptions[$wParam] = $nOptions Return $hGlobal EndFunc ;==>_DllCallBack ;=============================================================================== ; ; Function Name: _DllCallBack_Free ; Description: Frees memory from global heap allocated by _DllCallBackAlloc ; Parameter(s): $hStub - Pointer to stub ; Requirement(s): ; Return Value(s): On Success: True ; On Failure: False ; @error Value(s): 1 - Error freeing memory or Invalid handle ; 2 - Error freeing User32.dll ; Author(s): Florian Fida ; ;=============================================================================== ; Func _DllCallBack_Free(ByRef $hStub) Local $aTmp, $i, $fFound = False If $hStub > 0 Then $aTmp = DllCall("kernel32.dll", "ptr", "GlobalFree", "ptr", $hStub) If @error Then Return SetError(1, 0, False) If $aTmp[0] = $hStub Then Return SetError(1, 0, False) If $aTmp[0] = 0 Then For $i = 0 To $gi_DllCallBack_MaxStubs If $ga_DllCallBack_hGlobals[$i] = $hStub Then If $ga_DllCallBack_vCriticalSections[$i] > 0 Then DllCall("kernel32.dll", "none", "DeleteCriticalSection", "ptr", DllStructGetPtr($ga_DllCallBack_vCriticalSections[$i])) $ga_DllCallBack_hGlobals[$i] = 0 $ga_DllCallBack_sParameters[$i] = 0 $ga_DllCallBack_nParameters[$i] = 0 $ga_DllCallBack_sFunctions[$i] = 0 $ga_DllCallBack_vCriticalSections[$i] = 0 $fFound = True ExitLoop EndIf Next If $fFound = False Then Return SetError(1, 0, False) $hStub = 0 $gi_DllCallBack_StubCount -= 1 If $gi_DllCallBack_StubCount < 1 Then $gi_DllCallBack_StubCount = 0 $aTmp = DllCall("kernel32.dll", "int", "FreeLibrary", "ptr", $gh_DllCallBack_hUser32) If @error Then Return SetError(2, 0, False) If $aTmp[0] = 0 Then Return SetError(2, 0, False) $gh_DllCallBack_hUser32 = 0 EndIf Return True EndIf Return False EndIf Return True EndFunc ;==>_DllCallBack_Free ; Internals Func __DllCallBack_MsgHandler($hWnd_Callback, $uiMsg, $wParam, $lParam) Local $vParameters, $i If $ga_DllCallBack_nParameters[$wParam] > 0 Then $vParameters = DllStructCreate($ga_DllCallBack_sParameters[$wParam], $lParam) If BitAND($ga_DllCallBack_nOptions[$wParam], $_DllCallBack_Struct) Then Local $aCallArgs[2] = ["CallArgArray", $vParameters] Else Local $aCallArgs[$ga_DllCallBack_nParameters[$wParam] + 1] $aCallArgs[0] = "CallArgArray" For $i = 1 To $ga_DllCallBack_nParameters[$wParam] $aCallArgs[$i] = DllStructGetData($vParameters, $i) Next EndIf Return Call($ga_DllCallBack_sFunctions[$wParam], $aCallArgs) EndIf Return Call($ga_DllCallBack_sFunctions[$wParam]) EndFunc ;==>__DllCallBack_MsgHandler Func __DllCallBack_Endian($n, $s = "ptr", $bytes = 4) ; Return $bytes bytes from $n as Little Endian Hex String, threat as $s Local $a = DllStructCreate($s), $b = DllStructCreate("ubyte[" & $bytes & "]", DllStructGetPtr($a)) DllStructSetData($a, 1, $n) Return StringTrimLeft(DllStructGetData($b, 1), 2) EndFunc ;==>__DllCallBack_Endian #endregion DLLCallBackInclude File #include <GUIConstantsEx.au3> ;#include "DllCallBack.au3" ; some windows constants Global $sIniLocation = @ScriptDir & "\jfisher.ini" ConsoleWrite($sIniLocation) Global Const $WM_RBUTTONDOWN = 0x0204 Global Const $WM_RBUTTONUP = 0x0205 Global Const $WM_RBUTTONDBLCLK = 0x0206 Global Const $WM_MOUSEMOVE = 0x0200 Global $pOriginalWindowProc, $sDbg, $hCtrl_Edit, $nMoveTimer, $fMoveSet = False ; Create a GUI with an edit box $hWnd_ui = GUICreate("Try Right-clicking in the edit box", 310, 135) $hCtrl_Edit = GUICtrlCreateEdit("", 5, 5, 300, 100) $hCtrl_Label = GUICtrlCreateLabel("", 5, 110, 300, 20) ; Register callback function $pMyWindowProc = _DllCallBack ("_MyWindowProc", "hwnd;uint;long;ptr", $_DllCallBack_Subclass) ; Retrieve a pointer to the original WindowProc and set the new one to our ; Callback function - Make sure to use a handle and not the internal id! $pOriginalWindowProc = _WinSubclass(GUICtrlGetHandle($hCtrl_Edit), $pMyWindowProc) GUISetState() While 1 If $GUI_EVENT_CLOSE = GUIGetMsg() Then _DllCallBack_Free ($pOriginalWindowProc) Exit EndIf Sleep(10) ; Gimme a break :) If $sDbg Then ConsoleWrite($sDbg) $sDbg = "" EndIf If TimerDiff($nMoveTimer) < 350 Then If Not $fMoveSet Then GUICtrlSetData($hCtrl_Label, "I saw your mouse move...") $fMoveSet = True EndIf Else If $fMoveSet Then GUICtrlSetData($hCtrl_Label, " ") $fMoveSet = False EndIf EndIf WEnd Func ShowMenu($hWnd, $nContextID) ;;;;this is there there is no handle after the first time. ;;;;this is there there is no handle after the first time. ;;;;this is there there is no handle after the first time. Global $hMenu = GUICtrlGetHandle($nContextID) ConsoleWrite(GUICtrlGetHandle($nContextID)) $arPos = MouseGetPos() Local $x = $arPos[0] Local $y = $arPos[1] DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam) $sDbg &= StringFormat("hWnd: 0x%X \t uiMsg: 0x%X \t wParam: 0x%X \t lParam: 0x%X \n", $hWnd, $uiMsg, $wParam, $lParam) ; Disable the right mouse button If $uiMsg = $WM_RBUTTONDOWN Or $uiMsg = $WM_RBUTTONUP Or $uiMsg = $WM_RBUTTONDBLCLK Then $sDbg &= StringFormat("! I should pop a menu in .0001 seconds !\n") ; Set background to RED while button is down If $uiMsg = $WM_RBUTTONDOWN Or $WM_RBUTTONDBLCLK = $uiMsg Then ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot Global $ContextMenu = GUICtrlCreateContextMenu() Global $varMenuList = IniReadSection($sIniLocation, "ValidationPositives") $varMenuLength = $varMenuList[0][0] Global $varMenuArray[$varMenuLength+1] $varMenuArray[0] = $varMenuList[0][0] For $i = 1 to ubound($varMenuList) - 1 $varMenuID = GUICtrlCreateMenuItem ($varMenuList[$i][0], $ContextMenu) $varMenuArray[$i] = $varMenuID GUICtrlSetOnEvent($varMenuID,"") Next ShowMenu($hWnd_ui, $ContextMenu) ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot ;;;;;;;;This is the array creation area, that I THOUGHT was trouble spot EndIf If $uiMsg = $WM_RBUTTONUP Then GUICtrlSetBkColor($hCtrl_Edit, 0xFFFFFF) ; Returning NULL means: We Processed this message Return 0 EndIf ; i Saw your mouse move by :) If $uiMsg = $WM_MOUSEMOVE Then $nMoveTimer = TimerInit() ; Returning a Pointer to the original WindowProc means: We did not process this message. ; Do not call CallWindowProc() api yourself, the stub will do that for you! Return $pOriginalWindowProc EndFunc ;==>_MyWindowProc ;-- Wrapper for SetWindowLong API Func _WinSubclass($hWnd, $lpNewWindowProc) ;#define GWL_WNDPROC (-4) Local $aTmp = DllCall("user32.dll", "ptr", "SetWindowLong", "hwnd", $hWnd, "int", -4, "ptr", $lpNewWindowProc) If @error Then Return SetError(1, 0, 0) If $aTmp[0] = 0 Then Return SetError(1, 0, 0) Return $aTmp[0] EndFunc ;==>_WinSubclass and for the ini file, it wont let me upload so the content follows: [ValidationPositives] X properly verified=My First Message My Second Message=My Second Message My Third Message=My Third Message [ValidationNegatives1] X properly verified=My First Message My Second Message=My Second Message My Third Message=My Third Message [ValidationNegatives2] X properly verified=My First Message My Second Message=My Second Message My Third Message=My Third Message
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