#pragma compile(AutoItExecuteAllowed, True) #include-once #include #include #include #include #include ; #WCD_IPC UDF# ==================================================================================================================== ; Name ..........: PMT-UDF.au3 ; Description ...: Allows to start multiple processes (pseudo-threads) ; : Based on the functions included in the script ; Author ........: Nine ; Created .......: 2024-03-18 ; Modified ......: 2024-03-24 ; Remarks .......: See AutoIt Example Forum ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Func _PMT_Init ($sAutoItPath = "C:\Program Files (x86)\AutoIt3\", $sUDF = "PMT-UDF.au3") : Initialize PMT based on location of AutoIt3 and Name of the UDF ; Return : Number of Functions identified ; Func _PMT_Start($sFunc, $vP1 = Null, $vP2 = Null, $vP3 = Null, $vP4 = Null, $vP5 = Null, $vP6 = Null, $vP7 = Null, $vP8 = Null) ; : Start a new thread with up to 8 optional parameters ; Return : Id of the thread ; _PMT_GetResponse($iPID) : Get returned value from the thread ; Return : Message left by the thread ; =============================================================================================================================== Global $_PMT_mFunc[] Func _PMT_Init($sAutoItPath = "C:\Program Files (x86)\AutoIt3\", $sUDF = "PMT-UDF.au3") If $sAutoItPath = Default Then $sAutoItPath = "C:\Program Files (x86)\AutoIt3\" If $sUDF = Default Then $sUDF = "PMT-UDF.au3" Local $sProgram = @Compiled ? __PMT_GetSavedSource() : FileRead(@ScriptFullPath) If @error Then Return SetError(@error) Local $aInclude = StringRegExp($sProgram, '(?im)^\h*#include[<"\h].+', 3) If StringRight($sAutoItPath, 1) <> "\" Then $sAutoItPath &= "\" For $i = UBound($aInclude) - 1 To 0 Step -1 If StringInStr($aInclude[$i], $sUDF) Then _ArrayDelete($aInclude, $i) ContinueLoop EndIf If @Compiled Then __PMT_MakeFullPath($aInclude[$i], $sAutoItPath) Next Local $sInclude = _ArrayToString($aInclude, @CR) Local $aLine = StringSplit($sProgram, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT) Local $sName, $sFunc For $i = 0 To UBound($aLine) - 1 If StringRegExp($aLine[$i], "(?im)^\h*Func\h+\w+\h*\(\h*.*\)") Then $sName = StringRegExp($aLine[$i], "(?i)Func\h+(\w+)", 1)[0] $sFunc = "#NoTrayIcon" & @CRLF & $sInclude & @CRLF While Not StringRegExp($aLine[$i] & @CR, "(?is)^\h*EndFunc[\h;\v]") $sFunc &= $aLine[$i] & @CRLF $i += 1 WEnd $_PMT_mFunc[$sName] = $sFunc & $aLine[$i] & @CRLF & "ConsoleWrite(" & $sName & "(<>))" EndIf Next Return UBound(MapKeys($_PMT_mFunc)) EndFunc ;==>_PMT_Initialize Func _PMT_Start($sFunc, $vP1 = Null, $vP2 = Null, $vP3 = Null, $vP4 = Null, $vP5 = Null, $vP6 = Null, $vP7 = Null, $vP8 = Null) If Not MapExists($_PMT_mFunc, $sFunc) Then Return SetError(1) Local $sParam = "", $vValue For $i = 1 To 8 $vValue = Eval("vP" & $i) Switch VarGetType($vValue) Case "Bool", "Ptr", "Int32", "Double" $sParam &= $vValue & "," Case "String" $sParam &= '"' & $vValue & '",' Case "Keyword" If $vValue = Null Then ExitLoop $sParam &= "Default," Case Else Return SetError(2) EndSwitch Next If $i > 1 Then $sParam =StringTrimRight($sParam, 1) $sParam = StringReplace($_PMT_mFunc[$sFunc], "<>", $sParam) ;MsgBox($MB_OK, "Script", $sParam) Local $sFile = _TempFile(@ScriptDir, "~~", ".au3", 12) FileWrite($sFile, $sParam) Local $iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & $sFile, "", Default, $STDOUT_CHILD) ProcessWait($iPID, 5) FileDelete($sFile) Return $iPID EndFunc Func _PMT_GetResponse($iPID) Local $sRet = StdoutRead($iPID) If @error Then Return SetError(@error) Return $sRet EndFunc ; #INTERNAL FUNCTIONS#========================================================================================================== Func __PMT_GetSavedSource() Local $hInstance = _WinAPI_GetModuleHandle(Null) If Not $hInstance Then Return SetError(11) Local $hResource = _WinAPI_FindResource($hInstance, $RT_RCDATA, 999) If Not $hResource Then Return SetError(12) Local $hData = _WinAPI_LoadResource($hInstance, $hResource) Local $pResource = _WinAPI_LockResource($hData) Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource) Local $tBuffer = DllStructCreate('byte array[' & $iSize & ']', $pResource) _WinAPI_FreeLibrary($hInstance) Return BinaryToString($tBuffer.array) EndFunc ;==>_PMT_GetSavedSource Func __PMT_RemoveFileName($sPath) Return StringLeft($sPath, StringInStr($sPath, "\", 1, -1)) EndFunc Func __PMT_MakeFullPath(ByRef $sInclude, $sAutoItPath) If StringInStr($sInclude, '"') Then Return Local Static $sExec = __PMT_RemoveFileName(@AutoItExe) Local $sFile = StringRegExp($sInclude, "<(.*)>", 1)[0] If FileExists($sFile) Then Return If FileExists($sAutoItPath & "Include\" & $sFile) Then $sInclude = "#include <" & $sAutoItPath & "Include\" & $sFile & ">" Else $sInclude = "#include <" & $sExec & "Include\" & $sFile & ">" EndIf EndFunc