Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved]Expose Variable with a function ListGlobalVars()



  • Please log in to reply
2 replies to this topic
tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
what i want to do is just like ListVars with an exception instead of dumping it to the window. I want the list returned to the script.


Ideas?

ok so ill tell you why also

Any non blank com variables i may have declared and set in the script i want to make sure get released on script exit

i know there would be limitations like it would only work with globals but thats close enouph for me

thanks to all who contribute

my scripts are quite long and this is probably a lazy approach to fixing bad code but well its better than not dealing with it
conceptually
vardump,outarray
loop % varcount
if outarray%a_index% is integer ; yes not all integers are com objects but since there isnt currently an object var type its all i got and im not concerned with com functions that return strings
COM_Release(outarray%a_index%)

Never lose.
WIN or LEARN.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
✓  Best Answer
Have you already tried Lexikos' ListGlobalVars() ?

:)
kWo4Lk1.png

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
no mostly because im way to stupid to have found it in the search
thanks for helping a villiage idiot
final version of my code looks something like this
COM_Init()cleanup()
{
myvarlist :=  ListGlobalVars() 
loop parse, myvarlist, `n
{
	StringGetPos,myvar,A_LoopField,[	
	thisvar:=SubStr(A_LoopField,1,myvar)
	if thisvar
		if not thisvar = "ErrorLevel"
			if %thisvar% is Integer
			{
				StringLen,len,%thisvar%	
				IfEqual,len,8
					COM_Release(%thisvar%)
			}
}
}
ListGlobalVars() 
{ 
    static hwndEdit, pSFW, pSW, bkpSFW, bkpSW 
    
    if !hwndEdit 
    { 
        dhw := A_DetectHiddenWindows 
        DetectHiddenWindows, On 
        Process, Exist 
        ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %ErrorLevel% 
        DetectHiddenWindows, %dhw% 

        hmod := DllCall("GetModuleHandle", "str", "user32.dll") 
        pSFW := DllCall("GetProcAddress", "uint", hmod, "str", "SetForegroundWindow") 
        pSW := DllCall("GetProcAddress", "uint", hmod, "str", "ShowWindow") 
        DllCall("VirtualProtect", "uint", pSFW, "uint", 8, "uint", 0x40, "uint*", 0) 
        DllCall("VirtualProtect", "uint", pSW, "uint", 8, "uint", 0x40, "uint*", 0) 
        bkpSFW := NumGet(pSFW+0, 0, "int64") 
        bkpSW := NumGet(pSW+0, 0, "int64") 
    } 

    NumPut(0x0004C200000001B8, pSFW+0, 0, "int64")  ; return TRUE 
    NumPut(0x0008C200000001B8, pSW+0, 0, "int64")   ; return TRUE 
    
    ListVars 
    
    NumPut(bkpSFW, pSFW+0, 0, "int64") 
    NumPut(bkpSW, pSW+0, 0, "int64") 
    
    ControlGetText, text,, ahk_id %hwndEdit% 

    RegExMatch(text, "sm)(?<=^Global Variables \(alphabetical\)`r`n-{50}`r`n).*", text) 
    return text 
}

and usage like this
COM_Init()
mywin:=IE7_Get("google")
anothervar=123456
cleanup()


now feel free to call me an idiot and point out any problems here
the end goal will be to call this in a label onexit
Never lose.
WIN or LEARN.