#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.18.0 Author: Kanashius Script Function: Example script for the IPC InterProcessCommunication UDF. This example shows how datastructuress can be sent and received. #ce ---------------------------------------------------------------------------- #include "IPC.au3" #include "../ToString/ToString.au3" Global Const $iCOMMAND_START = 1, $iCOMMAND_END = 2, $iCOMMAND_DATA = 3 _SubProcess(1) Exit ; check if the call is a sub process and start the respective function __IPC_SubCheck("_SubProcess", "_MainProcess") If @error Then __IPC_Log($__IPC_LOG_ERROR, "__IPC_SubCheck: "&@error&":"&@extended) ; main/sub process both should call shutdown before exit __IPC_Shutdown() Exit ; registered as callback in __IPC_StartProcess to be called when data from the sub process is received ; the main process main method, registered in __IPC_SubCheck to be called when the script is running as main process (no sub process command line arguments detected) Func _MainProcess() ; start a sub process calling the same script. ; the _CallbackMain method is called for messages received from the sub process ; 100 is the parameter provided to the sub process (total items) Local $hProcess = __IPC_StartProcess("_CallbackMain", "11") ; wait for the sub process to finish While ProcessExists(__IPC_SubGetPID($hProcess)) And Sleep(10) WEnd EndFunc ; registered as callback in __IPC_StartProcess to be called when data from the sub process is received Func _CallbackMain($hSubProcess, $iCmd, $arData) ; $hSubProcess can be used to differentiate between different sub processes (if multiple are started with the same callback method) ; $data can be a string or binary data, depending on the data sent by the sub process ; $iCmd contains the command send by the server Switch $iCmd Case $iCOMMAND_START ConsoleWrite("Start processing"&@crlf) Case $iCOMMAND_END ConsoleWrite("Finished processing"&@crlf) Case $iCOMMAND_DATA ; Case Else ConsoleWrite("Unknown command ["&$iCmd&"]: "&UBound($arData)&@crlf) EndSwitch EndFunc ; the sub process main method, registered in __IPC_SubCheck to be called when the script is running as a sub process Func _SubProcess($hSubProcess) ; __IPC_SubSend($iCOMMAND_START) ; prepare example data Local $mData[], $mMap[] $mMap.test = 2 $mMap[100] = "dsa" $mData.map = $mMap Local $ar1D = [1, 2, 3, 4] $mData.arr1D = $ar1D Local $ar2D = [[1, 2], [3, 4]] $mData.arr2D = $ar2D Local $ar3D = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] $mData.arr3D = $ar3D $mData.binary = Binary(0xFF2312302343221) $mData.boolTrue = True $mData.boolFalse = False Local $tStruct = DllStructCreate("struct;int var1;byte var2;uint var3;char var4[128];endstruct") DllStructSetData($tStruct, "var1", -1) DllStructSetData($tStruct, 2, 255) DllStructSetData($tStruct, "var3", -1) DllStructSetData($tStruct, "var4", "Hello") $mData.dllStruct = $tStruct $mData.userFunc = _SubProcess $mData.func = ConsoleWrite $mData.float = 0.341234 $mData.hwnd = WinGetHandle(AutoItWinGetTitle()) $mData.int32 = 3213 $mData.int64 = Int(3213, 2) $mData.objDictionary = ObjCreate('Scripting.Dictionary') $mData.objDictionary.add("1", "eins") $mData.objDictionary.add(2, "zwei") ; $mData.object = ObjCreate("MediaPlayer.MediaPlayer.1") $mData.pointer = DllStructGetPtr($tStruct) $mData.string = "Something" $mData.keyword = Default __IPC__ToBinary($mData) Local $arKeys = MapKeys($mData) For $i=0 To UBound($arKeys)-1 ConsoleWrite("-----------"&$arKeys[$i]&"-----------"&@crlf) _compare($mData[$arKeys[$i]], __IPC__BinaryConsumeVar(__IPC__ToBinary($mData[$arKeys[$i]]))) Next ; __IPC_SubSend($iCOMMAND_DATA, $mData) ; __IPC_SubSend($iCOMMAND_END, "") EndFunc Func _compare($dataBefore, $dataAfter) ConsoleWrite(VarGetType($dataBefore)&": ") _ToStringC($dataBefore, False, "", "", " ") ConsoleWrite(VarGetType($dataAfter)&": ") _ToStringC($dataAfter, False, "", "", " ") EndFunc