[H] Passing objects between processes

Post your working scripts, libraries and tools for AHK v1.1 and older
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

[H] Passing objects between processes

15 May 2014, 08:14

FuncPost()

The main solution ahkFunction three Shortcoming:

1,Can not pass objects.
2,SendMessage clogging,Causing stagnation., Such as AhkThread.ahkFunction("Acc_Get",,,"")
3,Optional parameter is invalid
AhkThread.ahkFunction("Fuec") → Fuec(F:=1) → f=""

Code: Select all

AhkThread := AhkDllThread()
AhkThread.ahktextdll("
(LTrim %
#Persistent
Func(B,A:=3){
MsgBox % A
Return [1,2,A]
}
Func1(A:=8){
MsgBox % A
Return A
}

FuncPost_receive(f,s){
	s[f]:=IsFunc(f)? %f%((s:=Object(s))*) : """"
}

)")
MsgBox, % AhkThread.ahkFunction("Func1")
MsgBox, % FuncPost_send(AhkThread,"Func",8).3



FuncPost_send(m,f,s*){
	m.ahkPostFunction("funcPost_receive",f,r:=Object(s)),t:=A_TickCount
	while (A_TickCount - t < 1000) and !s.HasKey(f)
		Sleep,-1
	Return s[f]
}

Code: Select all

FuncPost_send(m,f,s*){
	m.ahkPostFunction("funcPost_receive",f,r:=Object(s)),t:=A_TickCount
	while (A_TickCount - t < 1000) and !s.HasKey(f)
		Sleep,-1
	Return s[f]
}

FuncPost_receive(f,s){
	s[f]:=IsFunc(f)? %f%((s:=Object(s))*) : ""
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [H] Passing objects between processes

15 May 2014, 14:49

  • 1. Object can be passed by address, but digits must be forced to string because only strings are supported.

    Code: Select all

    AhkThread.ahkFunction("Func",(&obj) "")
    ; In dll
    Func(p){
    obj:=IsObject(p)?p:Object(p+0)
    ...
    }
  • 2. Windows does not support calling COM via SendMessage.
  • 3. I have made some changes to ahkFunction a while ago but have not updated docs because I have no access currently.
    To omit parameters properly in v1 we need to define ahkFunction parameters as pointers and send pointers instead of string.

    Code: Select all

    dll:=MemoryLoadLibrary(A_ScriptDir "\AutoHotkey.dll")
    ahktextdll:=DynaCall(MemoryGetProcAddress(dll,"ahktextdll"),"i==sss")
    ahkFunction:=DynaCall(MemoryGetProcAddress(dll,"ahkFunction"),"s==stttttttttt")
    
    ahktextdll["
    (
    #Persistent
    Func(b,a:=3){
      static obj
      Return &obj:=[1,a,b]
    }
    )"]
    for k,v in Object(ahkFunction["Func",&"test"]+0)
      MsgBox % k ": " v
    To omit parameters in v2 we can use above method or simply pass 0 as next parameter:

    Code: Select all

    dll:=MemoryLoadLibrary(A_ScriptDir "\AutoHotkey.dll")
    ahktextdll:=DynaCall(MemoryGetProcAddress(dll,"ahktextdll"),"i==sss")
    ahkFunction:=DynaCall(MemoryGetProcAddress(dll,"ahkFunction"),"s==sssssssssss")
    
    ahktextdll["
    (
    #Persistent
    Func(b,a:=3){
      static obj
      Return &obj:=[1,a,b]
    }
    )"]
    for k,v in Object(ahkFunction["Func","test",0]+0)
      MsgBox % k ": " v
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: [H] Passing objects between processes

15 May 2014, 15:37

does FuncPost() overcome the aforementioned issues raised by HotKeyIt? :ugeek:
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [H] Passing objects between processes

15 May 2014, 23:28

1, if the target function is not determined, and there is a large number of parameters, this method is cumbersome. Because each parameter must determine whether the object.
2, this function is mainly for this limitation.
3, the objective function must use the "static". In addition, this method could as the default behavior, rather than requiring special treatment?

@Guest10 It bypasses these problems.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [H] Passing objects between processes

16 May 2014, 03:02

Btw. it is also possible to exchange COM Array between threads when using COM Interface (v1 unicode):

Code: Select all

ahk:=ComObjDll(MemoryLoadLibrary(A_AhkScript "\AutoHotkey.dll"),"{C58DCD96-1D6F-4F85-B555-02B7F21F5CAF}")
ahk.ahktextdll("#Persistent`nfun(p){`nMsgBox % ""From thread: "" p.0 ""-"" p.1`n}")
arr := ComObjArray(VT_VARIANT:=12, 3)
arr.0 := 1,arr.1 := "test"
ahk.ahkFunction("fun",arr)
MsgBox end
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [H] Passing objects between processes

16 May 2014, 07:56

Thanks.
H will solve these problems? ahkFunction these functions itself.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [H] Passing objects between processes

17 May 2014, 05:15

arcticir wrote:H will solve these problems? ahkFunction these functions itself.
I don't think so :(

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ArkuS and 124 guests