Jump to content

Very Simple Inter-Process Communication (using AutoItObject_Internal)


SEuBo
 Share

Recommended Posts

I didn't tested it yet, but can we pass arrays, objects that way?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

4 hours ago, MrCreatoR said:

I didn't tested it yet, but can we pass arrays, objects that way?

Hey,

yes you can, see example for array & object (in array) below - I think problems only really occur with DLLStructs, Pointers and Function-References. Some types (like handles) have to be Hwnd()'ed again on the other side. As far as I understood, those are internal limitations. Larsj did a great job summarizing it here (scroll down to "data types"):

$aArray :     Array variable type.
$dBinary :    Binary variable type.
$bBoolean :   Bool variable type.
$pPtr :       Int32 variable type.
$hWnd :       Int32 variable type.
$iInt :       Int32 variable type.
$fFloat :     Double variable type.
$oObject :    Object variable type.
$sString :    String variable type.
$tStruct :    Not recognized as a valid variable type.
$vKeyword :   Keyword variable type.
fuMsgBox :    Not recognized as a valid variable type.
$fuFunc :     Not recognized as a valid variable type.
$fuUserFunc : Not recognized as a valid variable type.

 

Example SharedData4:

Spoiler
#include "AutoItSharedData.au3"

$oShare = _AutoIt_SharedData_CreateOrAttach("ArrayTest")

$iPID1 = Run(StringFormat('%s /AutoIt3ExecuteScript "%s"', @AutoItExe, @ScriptDir & '\Example_sharedata4_Script1.au3'), @ScriptDir)
$iPID2 = Run(StringFormat('%s /AutoIt3ExecuteScript "%s"', @AutoItExe, @ScriptDir & '\Example_sharedata4_Script2.au3'), @ScriptDir)

$hGUI = GUICreate("", 400, 400)
$hList = GUICtrlCreateList("", 0, 0, 400,400)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            ProcessClose($iPID1)
            ProcessClose($iPID2)
            Exit
        Case Else

            If IsArray($oShare.arraydata) Then
                GUICtrlSetData($hList, StringFormat("%s: (%s) %s", $oShare.arraydata[0], $oShare.arraydata[1], $oShare.arraydata[2].random))
                $oShare.arraydata = 0
            EndIf

            Sleep(10)
    EndSwitch
WEnd

 

Sub-Script Example_sharedata4_Script1:

#include "AutoItSharedData.au3"
#include <Date.au3>

$oShare = _AutoIt_SharedData_CreateOrAttach("ArrayTest")


_AutoItObject_Startup()
$oObject = _AutoItObject_Create()
_AutoItObject_AddProperty($oObject, 'random')


Global $aArray[3]


While 1
    $aArray[0] = _NowCalc() & ":" & @MSEC
    $aArray[1] = 'Script #1'
    $aArray[2] = $oObject

    $oObject.random = Random(1, 25, 1)
    $oShare.arraydata = $aArray


    Sleep(Random(10, 300,1))
WEnd

Sub-Script Example_sharedata4_Script2:

#include "AutoItSharedData.au3"
#include <Date.au3>

$oShare = _AutoIt_SharedData_CreateOrAttach("ArrayTest")


_AutoItObject_Startup()
$oObject = _AutoItObject_Create()
_AutoItObject_AddProperty($oObject, 'random')


Global $aArray[3]


While 1
    $aArray[0] = _NowCalc() & ":" & @MSEC
    $aArray[1] = 'Script number two'
    $aArray[2] = $oObject

    $oObject.random = Random(300, 400)
    $oShare.arraydata = $aArray


    Sleep(Random(10, 300,1))
WEnd

 

384233565_GIF12_02.202119-20-33.gif.15aa26b83e1fac118871384269ab7963.gif

Edited by SEuBo
Link to comment
Share on other sites

Great, i will test it soon, thanks for sharing!

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

New Version.

Since AutoItObject Internal now comes with ROT support, I removed the need for AutoItObject. No Dlls anymore, and most notably: 64-Bit support. Archive in first post updated.

 

Link to comment
Share on other sites

Thanks for sharing. Intriguing stuff that I just might use one day ... I see the possibilities.

Of course, like many I suspect, I have shared data between programs using an INI file entry or a Registry entry, probably even via SQL. I've also done it using STDOUT and STDIN by compiling to a console based executable. Your project however seemingly promises more and better. :)

Cheers

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

2 hours ago, TheSaint said:

Thanks for sharing. Intriguing stuff that I just might use one day ... I see the possibilities.

Of course, like many I suspect, I have shared data between programs using an INI file entry or a Registry entry, probably even via SQL. I've also done it using STDOUT and STDIN by compiling to a console based executable. Your project however seemingly promises more and better. :)

Cheers

Thanks for you kind words. I didn't do much but to stumble accross this (Even a blind squirrel finds a nut once in a while :)but I am glad you like it!

All credits go to @genius257 for AutoItObject_Internal and of course to the original AutoItObject-Team for their great effort.

Link to comment
Share on other sites

From me as well : "Thanks for sharing" :thumbsup:

1 hour ago, SEuBo said:

I didn't do much but to stumble accross this (Even a blind squirrel finds a nut once in a while :))

That is true, but it makes a big difference whether the nut is made of gold or is rotten. Moreover, finding something is only the first step. There must also be someone willing to spend his time to prepare something delicious from it (as you did) :D.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Thank you SEuBo, very useful!

I found these limits with array:

you can set and change a string/number var etc, you can read array, but you can't set/change an array and you can't directly use UDF _array: i.e. _arrayDisplay($oShare.arr)

#include "AutoItShared/AutoItSharedData.au3"
#include <Array.au3>

$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")

$oShare.data = 'foo'

global $arr = [1,2]
;global $oShare.arr = [1,2] ; NO

$arr[1] = 4
$oShare.arr = $arr
msgbox(0,'', $oShare.arr[1]) ; OK
;~ $oShare.arr[1] = 5 ; NO

_arrayDisplay($arr) ; OK
;~ _arrayDisplay($oShare.arr) ; NO

can you overcome these?

Link to comment
Share on other sites

Hey frank10,

those are unfortunately limitations of the AutoIt Parser, as far as I understand. 

I guess you have no chance, but to use a temporary variable.

 

Regarding the direct access of Array-Elements for writing, there is a potential workaround, which is still not pretty.
We could "fake" a method for all the Array data. This would be done by replacing your AutoItSharedData.au3 with the following file (for testing purposes:)

Spoiler
#include-once
#include <AutoItObject_Internal.au3>
#include <AutoItObject_Internal_ROT.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: _AutoIt_SharedData_CreateOrAttach
; Description ...: Creates an IDispatch-Object as a shared storage object
; Syntax ........: _AutoIt_SharedData_CreateOrAttach($sID)
; Parameters ....: $sID     - ID of shared storage. Can be any alphanumerical string.
; Return values .: | Success: $oObject; an IDispatch Instance.
; ...............: | Failure: sets @error to non-zero
; Author ........: SEuBo
; Remarks .......: Version 2.0
; Link ..........: https://www.autoitscript.com/forum/topic/205109-very-simple-inter-process-communication-using-autoitobject-pure-autoit/
; ===============================================================================================================================
Func _AutoIt_SharedData_CreateOrAttach($sID)
    Local Const $cMonikerPrefix = 'AutoIt._AutoItSharedData.'
    Local $oObject

    $oObject = ObjGet($cMonikerPrefix & $sID)
    If Not IsObj($oObject) Then
        $oObject = IDispatch(QueryInterface, AddRef, Release, GetTypeInfoCount, GetTypeInfo, GetIDsOfNames, __AutoIt_SharedData_Invoke)
        _AOI_ROT_Register($oObject, $cMonikerPrefix & $sID, True)
        If @error Then $oObject = ObjGet($cMonikerPrefix & $sID)
    EndIf

    Return SetError(@error, @extended, $oObject)
EndFunc   ;==>_AutoIt_SharedData_CreateOrAttach


Func __AutoIt_SharedData_Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
    If $dispIdMember <= 0 Then
        Return Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
    Else

        Local $tHelperProperty, $iArguments, $oHelper, $vThisValue
        Local $sArrayAccess
        Local $pThisProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + __AOI_GetPtrOffset("Properties")), 1)
        Local $tThisProperty = DllStructCreate($tagProperty, $pThisProperty)

        For $i = 1 To $dispIdMember - 1
            $pThisProperty = $tThisProperty.Next
            $tThisProperty = DllStructCreate($tagProperty, $pThisProperty)
        Next

        If (BitAND($wFlags, $DISPATCH_PROPERTYGET) = $DISPATCH_PROPERTYGET) And Not ($tThisProperty.__getter = 0) Then Return Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
        If (BitAND($wFlags, $DISPATCH_PROPERTYPUT) = $DISPATCH_PROPERTYPUT) And Not ($tThisProperty.__setter = 0) Then Return Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)

        $tVARIANT = DllStructCreate($tagVARIANT)
        $tDISPPARAMS = DllStructCreate($tagDISPPARAMS, $pDispParams)

        $oHelper = IDispatch()
        $oHelper.variant_value = 0
        $tHelperProperty = DllStructCreate($tagProperty, DllStructGetData(DllStructCreate("ptr", Ptr($oHelper) + __AOI_GetPtrOffset("Properties")), 1))

        VariantCopy($tHelperProperty.Variant, $tThisProperty.Variant)
        $vThisValue = $oHelper.variant_value
        If IsArray($vThisValue) And $tDISPPARAMS.cArgs > 1 Then
            Local $aMap[$tDISPPARAMS.cArgs + 1]
            For $i = 1 To $tDISPPARAMS.cArgs
                VariantCopy($tHelperProperty.Variant, Ptr($tDISPPARAMS.rgvargs + (($tDISPPARAMS.cArgs - $i) * DllStructGetSize($tVARIANT))))
                If $i < $tDISPPARAMS.cArgs Then $aMap[$i] = $oHelper.variant_value
            Next

            Switch $tDISPPARAMS.cArgs - 1
                Case 1
                    $vThisValue[$aMap[1]] = $oHelper.variant_value
                Case 2
                    $vThisValue[$aMap[1]][$aMap[2]] = $oHelper.variant_value
                Case 3
                    $vThisValue[$aMap[1]][$aMap[2]][$aMap[3]] = $oHelper.variant_value
                Case 4
                    $vThisValue[$aMap[1]][$aMap[2]][$aMap[3]][$aMap[4]] = $oHelper.variant_value
                Case 5
                    $vThisValue[$aMap[1]][$aMap[2]][$aMap[3]][$aMap[4]][$aMap[5]] = $oHelper.variant_value
                Case Else
                    Return $DISP_E_BADPARAMCOUNT
            EndSwitch

            $oHelper.variant_value = $vThisValue
            VariantCopy($tThisProperty.Variant, $tHelperProperty.Variant)
            SetError(@error, @extended)

            VariantClear($pVarResult)
            VariantCopy($pVarResult, $tHelperProperty.Variant)

            Return $S_OK
        EndIf

        Return Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
    EndIf
EndFunc   ;==>__AutoIt_SharedData_Invoke

 

Instead of

;~ $oShare.arr[1] = 5 ; NO

you could then write:

$oShare.arr(1) = 5

 

Not great, but at least something.

Link to comment
Share on other sites

1 hour ago, SEuBo said:

Regarding the direct access of Array-Elements for writing, there is a potential workaround, which is still not pretty.

We could "fake" a method for all the Array data. This would be done by replacing your AutoItSharedData.au3 with the following file (for testing purposes:)

Instead of


;~ $oShare.arr[1] = 5 ; NO

you could then write:


$oShare.arr(1) = 5

 

Great, a lot better!

It works also with 2D array:

global $arr = [[1,2],[3,4]]
$arr[1][0] = 8
$oShare.arr = $arr
$oShare.arr(1,1) = 9 

$temp = $oShare.arr
_arrayDisplay($temp)

 

Link to comment
Share on other sites

Could you explain why I am receiving this error :

image.png.8fa30211e54bcacaf3829552efe03092.png

Test1.au3 :

#include "AutoItSharedData.au3"

$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")

$oShare.Request = @MSEC

Do
    Sleep(10)
Until $oShare.Response

MsgBox(64,"",$oShare.Request & "/" & $oShare.Response)

Test2.au3 :

#include <AutoItSharedData.au3>

$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")

Do
    Sleep(10)
Until $oShare.Request

$oShare.Response = @MSEC

If I run Test2 first, and then Test1 I get the error.  

Link to comment
Share on other sites

Hi Nine,

contrary to what I've said in the first post about "the first script accessing a variable":

My best guess is that because Test2.au3 is the last script to assign any value within $oShare, it becomes the "Server" for this IDispatch.
Even though the behaviour isn't really consistent. I'd have to dig into that.

Potential workarounds:

1) Add Sleep(100) as last line of Test2.au3, like so:

#include <AutoItSharedData.au3>

$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")

Do
    Sleep(10)
Until $oShare.Request

$oShare.Response = @MSEC
Sleep(100)

2) OR: Add Error-Handler into Scripts, like so:

#include "AutoItSharedData.au3"

$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")
$oError = ObjEvent("AutoIt.Error", _ErrorHandler)

$oShare.Request = @MSEC

Do
    Sleep(10)
Until $oShare.Response

MsgBox(64,"",$oShare.Request & "/" & $oShare.Response)


func _ErrorHandler($oObject)
    SetError($oObject.number)
EndFunc

 

I'll investigate this later today.

Cheers,

Link to comment
Share on other sites

There is also a problem with handles:

local $hWin = WinGetHandle("[active]")
$oShare.hGUImain  = $hWin ; it also stores it in Decimal...
ConsoleWrite($hWin & "___" & Hex($oShare.hGUImain) & @CRLF)
Local $aGUI_Main_Pos = WinGetPos($hWin)
ConsoleWrite("Pos hWin:"  & $aGUI_Main_Pos[0]  & @CRLF)

Local $aGUI_Main_Pos = WinGetPos($oShare.hGUImain)
ConsoleWrite("Pos oShare:"  & $aGUI_Main_Pos[0] & @CRLF) ; ERR
 
Local $aGUI_Main_Pos = WinGetPos( HWND($oShare.hGUImain) ) ; THIS works
ConsoleWrite("Pos oShare:"  & $aGUI_Main_Pos[0] & @CRLF) ; OK

EDIT

You should detect if there is a handle and store it as 0xHexNumber into the share var.

Edited by frank10
Link to comment
Share on other sites

I would like to change some control settings of a GUI created from another script.

I got Get/Set with ControlGetText and ControlSetText, because original funcs like GUICtrlRead does not work in the script that didn't create the GUI.

Is there a way to use those original funcs also in the other script?

i.e. GUICtrlSetBkColor or GUICtrlSetImage

 

Edited by frank10
Link to comment
Share on other sites

  • 3 months later...

Is there a limit on the number and long of "variables"?
I mean $oShare.xxx.

Is there a command to erase the values of all variables of $oShare ?

 

Edited by Lion66
add question
Link to comment
Share on other sites

  • 2 weeks later...

I'm still looking, how clean all data from Object without destroy it.
I found function VariantClear, but how I get list of all variables into object ?
Does anyone understand to help me?

Edited by Lion66
Link to comment
Share on other sites

This is the first time I have used AutoitObject.
I'm not sure if my question is related to this UDF, or if it is a more general question about Objects.
I'll ask here. Help me 🙂.
How to set the name and value of an object variable through function parameters?

#include "AutoItSharedData.au3"
$oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID")

_SharingSetData("1", "aaa")

Func _SharingSetData($Var, $String)

    $oShare.Variable($Var) = $String

    MsgBox(0,"", $oShare.Variable1)
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...