Launch Function & Catch Object in DllThread

Ask for help, how to use AHK_H, etc.
rommmcek
Posts: 623
Joined: 15 Aug 2014, 15:18

Launch Function & Catch Object in DllThread

15 Jul 2019, 05:51

A fellow member has infected me with AutoHotkey_H. Ironically it's me trying to help him.
I can launch function from dllThread and catch its value if the function returns number or string.
If the function returns object I'm lost.

Code: Select all

;MsgBox % "Main Var:`n" var(3, 5) ; works

;for i, j in obj(0, 1) ; works
    ;MsgBox % "Main Obj:`n" i ": " j

test := "
(
    test := AhkExported()
    ;MsgBox `% ""test Var:``n"" test.ahkFunction(""var"", 3 """", 5 """") ; \/ (works for numbers & strings, but not for objects)
    
    ;CritObj := CriticalObject({""answer"": 0, ""on"": 1}) ; \/ (works, but need to call 'ahkFuntion()'!)
    
    ;init:=test.ahkFunciton(""add"", 0 """", 1 """") ; ?????????????
    ;CritObj := CriticalObject(init) ; ??????????????
    CritObj := CriticalObject( test.ahkFunction(""obj"", 0 """", 1 """") ) ; //// (desn't work!!!)
    
    for i, j in CritObj
        MsgBox `% ""test Obj:``n"" i "":  "" j
)"

AhkDll := AhkThread(test, &CritObj)

While AhkDll.ahkReady()
    Sleep 100
SoundBeep, 8000
ExitApp
return

obj(a, b) {
	;return StrSplit(a "," b, ",")
	return {"answer": a, "on": b}
}

var(a, b) {
    Return a+b
}
For the reason of saving my time, Thanks for any hint!
rommmcek
Posts: 623
Joined: 15 Aug 2014, 15:18

Re: Launch Function & Catch Object in DllThread

15 Jul 2019, 16:10

This is my workaround:

Code: Select all

for i, j in obj(3, 5)
    MsgBox % "Main Obj:`n" i ": " j

test := "
(
    test := AhkExported()
    strObj := test.ahkFunction(""obj2Str"", 3 """", 5 """")
    loop, parse, strObj, ""``n""
        if A_LoopField
            MsgBox `% ""test Obj:``n"" StrReplace(A_LoopField, "","", "": "")
)"

AhkDll := AhkThread(test)

While AhkDll.ahkReady()
    Sleep 100
SoundBeep, 8000
ExitApp
return

obj2Str(a, b) {
    for i, j in obj(a, b)
        ar.=i "," j "`n"
    Return ar? RTrim(ar, "`n"): 0
}

obj(a, b) {
    SoundBeep, 1000
	return {"answer": a, "on": b}
}
If somebody has a 'cleaner' way to do it, I'll certainly take a look!
rommmcek
Posts: 623
Joined: 15 Aug 2014, 15:18

Re: Launch Function & Catch Object in DllThread

22 Jul 2019, 05:36

@HotKeyIt: Thanks for the hint!
Unfortunately as an amateur, I'm not able to update non of the code I found in order to work on current version of AutoHotkey_H.
If somebody doesn't provide working code I'll have to pass.
HotKeyIt
Posts: 1866
Joined: 29 Sep 2013, 18:35
Contact:

Re: Launch Function & Catch Object in DllThread

22 Jul 2019, 19:19

Code: Select all

SetBatchlines,-1
fun:=Func("Obj")
for i, j in fun.(3, 5)
    MsgBox % "Main Obj:`n" i ": " j

test := "
(
	SetBatchlines,-1
	fun:=Object(" (&fun) ")
    for i, j in fun.(3, 5)
            MsgBox `% ""test Obj:``n"" i "": "" j
)"

AhkDll := AhkThread(test)

While AhkDll.ahkReady()
    Sleep 100
SoundBeep, 8000
ExitApp

obj(a, b) {
    SoundBeep, 1000
	return {answer: a, on: b}
}
rommmcek
Posts: 623
Joined: 15 Aug 2014, 15:18

Re: Launch Function & Catch Object in DllThread

24 Jul 2019, 04:14

Thank you HotKeyIt!
It seems you adapted the advice to my level! Works perfect!

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 5 guests