Jump to content
LarsJ

Implementing IRunningObjectTable Interface

Recommended Posts

Posted (edited)

Hi @LarsJ, thanks for this udf, it looks very powerful ...I'm already playing it ...
I'm posting this just for a small problem on the examples

in the part that starts another script, namely:

; Start child
ShellExecuteWait( "2) Child.au3" )


it may not work as expected if AutoIt was installed with the "edit a script" option instead of "running a script" on a double click or shellexecute() on an .au3 file (as in my case)
in that case, you can use something like this instead using Run or RunWait as appropriate, i.e. depending on ShellExecute or ShellExecuteWait:

; Start child
RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & '"2) Child.au3"')

Thanks again

Edited by Chimp
changed Run with RunWait

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
Posted (edited)

Usage
An obvious use of ROT objects is in connection with tasks such as inter-process communication (IPC) and job processing. The advantage of using ROT objects for these tasks is partly that you can handle large amounts of data and partly that you can handle the vast majority of AutoIt data types.

Using a ROT object it's very easy to transfer arrays between two different processes. At the same time, the internal data types of the array elements are preserved. If an array containing integers, floats, and strings is passed from a sender to a recipient, then it's still integers, floats, and strings at the recipient. This means that the recipient can sort the array with exactly the same result as a sort of the array at the sender.

Not just simple data types are preserved. If an array element contains another array (embedded array) or an object (embedded object), then this embedded array or object is still valid at the recipient.

ROT objects are based on COM techniques. How is it possible that proprietary AutoIt data types such as arrays, can be transferred between a sender process and a receiver process using a technique based on standard COM data types? This is possible because the AutoIt array is converted to a safearray of variants (default COM array) at the sender and converted back to an AutoIt array at the receiver. But en route between sender and recipient it's a safearray. These conversions are performed automatically by internal AutoIt code (compiled C/C++ code, very fast). If you are interested you can find more information on these topics in Accessing AutoIt Variables.
 

Passing array between AutoIt programs
Examples\2) IPC Demo\Array\ contains two files that very simply demonstrate the exchange of arrays between programs running in two different processes. The example is a copy of the example in this thread but implemented with the new IRunningObjectTable UDF.

1) Server.au3:

#include <Array.au3>
#include "..\..\..\Includes\IRunningObjectTable.au3"

Example()

Func Example()
  MsgBox( 0, "Server", "This is server" )

  Local $sDataTransferObject = "DataTransferObject" & ROT_CreateGUID()
  ROT_RegisterObject( Default, $sDataTransferObject ) ; Default => Object = Dictionary object
  Local $oDataTransferObject = ObjGet( $sDataTransferObject ) ; Dictionary object

  ; Create array
  Local $aArray[1000][10]
  For $i = 0 To 1000 - 1
    For $j = 0 To 9
      $aArray[$i][$j] = $i & "/" & $j
    Next
  Next
  _ArrayDisplay( $aArray, "Array on server" )

  ; Transfer data
  $oDataTransferObject.Add( "$aArray", $aArray )

  ; Start client
  RunWait( @AutoItExe & " /AutoIt3ExecuteScript " & '"2) Client.au3" ' & $sDataTransferObject )


  ; ------- Server waiting while client is executing -------


  MsgBox( 0, "Server", "This is server again" )

  ; Receive data on server
  $aArray = $oDataTransferObject.Item( "$aArray" )
  _ArrayDisplay( $aArray, "Modified array on server" )
EndFunc

2) Client.au3:

#include <Array.au3>

Example()

Func Example()
  MsgBox( 0, "Client", "This is client" )

  ; Data transfer object
  Local $sDataTransferObject = $CmdLine[1]
  Local $oDataTransferObject = ObjGet( $sDataTransferObject )

  ; Receive data on client
  Local $aArray = $oDataTransferObject.Item( "$aArray" )
  _ArrayDisplay( $aArray, "Array on client" )

  ; Modify array on client
  For $i = 0 To 100 - 1
    $aArray[$i][0] = "Modified"
    $aArray[$i][1] = "on"
    $aArray[$i][2] = "client"
  Next
  _ArrayDisplay( $aArray, "Modified array on client" )

  ; Transfer data
  $oDataTransferObject.Item( "$aArray" ) = $aArray
EndFunc

 

Passing array between AutoIt and VBScript
Because ROT objects are based on standard COM code, it's possible to exchange data between an AutoIt program and other COM compatible programs e.g. VBScript. The files in Examples\3) IPC Demo2\VBScript\ demonstrate this:

1) Server.au3:

#include <GUIConstantsEx.au3>
#include "..\..\..\Includes\IRunningObjectTable.au3"

Example()

Func Example()
  Local $sArray = "ArrayData"
  ROT_RegisterObject( Default, $sArray ) ; Default => Object = Dictionary object
  Local $oArray = ObjGet( $sArray ) ; Dictionary object
  Local $aArray = [ 123, 123.123, "This is data from AutoIt" ]
  $oArray( "Array" ) = $aArray

  Local $sText = "Data exchange between AutoIt and VBScript"
  Local $hGui = GUICreate( $sText, 400, 300 )

  $sText = "Run Client.vbs:" & @CRLF & _
           "Open a Command Prompt in the current folder." & @CRLF & _
           "Key in ""wscript Client.vbs"" and hit the Enter key." & @CRLF & @CRLF & _
           "When you have seen the information in the MsgBox, press the button below."
  GUICtrlCreateLabel( $sText, 20, 60, 360, 80 )

  $sText = "Press Button to continue"
  Local $idButton = GUICtrlCreateButton( $sText, 20, 180, 360, 30 )

  GUISetState( @SW_SHOW, $hGui )

  While 1
    Switch GUIGetMsg()
      Case $idButton
        $aArray = $oArray( "Array" )
        MsgBox( 0, "AutoIt: Array from VBScript", "Int: " & $aArray[0] & "  (" & VarGetType( $aArray[0] ) & ")" & @CRLF & _
                                                  "Flt: " & $aArray[1] & "  (" & VarGetType( $aArray[1] ) & ")" & @CRLF & _
                                                  "Str: " & $aArray[2] & "  (" & VarGetType( $aArray[2] ) & ")" )

      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  GUIDelete( $hGui )
EndFunc

Client.vbs:

Dim oArray, iAnswer
Set oArray = GetObject( "ArrayData" )

iAnswer = MsgBox( "Int: " & oArray( "Array" )(0) & vbCrLf & _
                  "Flt: " & oArray( "Array" )(1) & vbCrLf & _
                  "Str: " & oArray( "Array" )(2), 0, "VBScript: Array from AutoIt" )

Dim aArray
aArray = Array( 234, 234.234, "This is data from VBScript" )

oArray( "Array" ) = aArray

Examples with programs like C# and VB.NET are probably more interesting than VBScript. This way, you can transfer (large) arrays from AutoIt to C# and VB.NET, perform array calculations in compiled code, and return arrays or results back to AutoIt. Here, the AutoIt and C#/VB.NET code are standalone programs that run in their own processes and are connected only through the ROT object.

It's a new option to execute code sections that are bottlenecks in interpreted AutoIt code as compiled and possibly multithreaded C#/VB.NET code.

Note that such a technique is very different from the technique in Using C# and VB Code in AutoIt through the .NET Framework, where all code runs in the same process.
 

Passing data through ROT Objects  (2020-07-11)
In IPC Techniques through ROT Objects (Data types section) the AutoIt data types have been tested based on the example for the VarGetType() function in the help file. The data types are sent from Sender to Receiver with these results:

$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.

Only the $tStruct and the function data types are not received correctly. The Int32 types for $pPtr and $hWnd can easily be converted to pointer and window handles with the Ptr() and HWnd() functions. In the following section (DllStruct section) it's shown how the $tStruct can be sent by converting the DllStruct to Binary data.

In the Large array section (still in the IPC Techniques example) it's shown that even very large arrays can be passed with ROT objects.

AutoIt/Perl integration is an example showing how to pass data back and forth between AutoIt and Perl scripts. Also between different programming languages, the data types are preserved with this technique.

Edited by LarsJ
Last section

Share this post


Link to post
Share on other sites

Great, this UDF is a great support for data transfer between processes 😍Thank you 😚

Share this post


Link to post
Share on other sites

The first post (ROT objects section) and the third post (last section) have been updated. New 7z-file at bottom of first post.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...