Popular Post LarsJ Posted July 11, 2020 Popular Post Share Posted July 11, 2020 (edited) I'm mainly using two scripting languages: AutoIt and Perl. Today I'm mostly using AutoIt. In the past mostly Perl. I've long had an idea of integrating AutoIt and Perl to be able to generate and collect data in Perl scripts and display data in AutoIt GUIs. Over the past few months, I've been working on examples about ROT objects and their use in IPC techniques. I've tested the ideas with regard to AutoIt/Perl integration. It seems to work. Install PerlTo use the Perl programming language on a Windows PC, the program must be installed. I'm using ActivePerl from ActiveState. An alternative distribution is Strawberry Perl. ActivePerl seems to be the easiest to use. Strawberry Perl is more advanced and includes a complete C/C++ compiler. The interesting Perl module for AutoIt/Perl integration is the Win32::OLE module. It's the module that makes Perl a COM compatible programming language. Remember to add this module to your Perl installation. PerlScript Be careful not to confuse Perl with PerlScript. PerlScript is a Perl module developed by ActiveState and is only a small part of the ActivePerl package for Windows. PerlScript is an ActiveX Scripting Engine for the Perl language to use Perl to create dynamic content on the Microsoft web server (in the same way as it can be done with VBScript and JScript). First attemptServer.au3 (Examples\0) First attempt\): #include <GUIConstantsEx.au3> #include "..\..\Includes\IRunningObjectTable.au3" Example() Func Example() Local $hGui = GUICreate( "AutoIt/Perl integration", 300, 100 ) Local $sText = "Run Client.pl:" & @CRLF & _ "Open a Command Prompt in current folder." & @CRLF & _ "Key in ""Perl Client.pl"" and hit the Enter key." & @CRLF & _ "Or ""Perl Client.pl >Client.txt"" to get output in file." GUICtrlCreateLabel( $sText, 20, 20, 260, 60 ) GUISetState( @SW_SHOW, $hGui ) Local $sDataTransfer = "DataTransfer" ROT_RegisterObject( Default, $sDataTransfer ) ; Default => Object = Dictionary object While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete( $hGui ) EndFunc In the first attempt, we'll simply test whether the GetObject() function in a Perl script is at all able to recognize the ROT object (the dictionary object), and thus return something similar to a dictionary object. This is more or less the same as we did in the VBScript example in the bottom half of this post. So far, no data is stored in the ROT object. This Perl snippet copied from Win32::OLE can be used to test whether the ROT object is recognized. The code snippet prints object and class information: Win32::OLE->EnumAllObjects( sub { my $Object = shift; my $Class = Win32::OLE->QueryObjectType( $Object ); printf "Object = %s, Class = %s\n", $Object, $Class; } ); Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); Win32::OLE->EnumAllObjects( sub { my $Object = shift; my $Class = Win32::OLE->QueryObjectType( $Object ); printf "Object = %s, Class = %s\n", $Object, $Class; } ); Output: Object = Win32::OLE=HASH(0x71b5a8), Class = IDictionary It looks good. The ROT object is recognized as a kind of HASH object (sometimes called associative array, dictionary or map) of class IDictionary. This corresponds to the fact that the ROT object is actually a dictionary object. Data from AutoIt to PerlSimple dataNow we can store simple data in the ROT object this way.Server.au3 (Examples\1) AutoIt to Perl\1) Simple data\): Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object $oDataTransfer( "$iInt" ) = 123 $oDataTransfer( "$fFlt" ) = 123.456 $oDataTransfer( "$sStr" ) = "String" Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); print "$oObj->{'$iInt'}\n"; print "$oObj->{'$fFlt'}\n"; print "$oObj->{'$sStr'}\n"; Output: 123 123.456 String 1D arrayServer.au3 (Examples\1) AutoIt to Perl\2) 1D array\): Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $aArray = [ 123, 123.456, "String" ] $oDataTransfer( "$aArray" ) = $aArray Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); print "@{$oObj->{'$aArray'}}\n"; Output: 123 123.456 String Note that internal data types of array elements are preserved. 2D arrayServer.au3 (Examples\1) AutoIt to Perl\2) 2D array\): Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $aArray[1000][10] For $i = 0 To 1000 - 1 For $j = 0 To 10 - 1 $aArray[$i][$j] = $i & "/" & $j Next Next $oDataTransfer( "$aArray" ) = $aArray Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); foreach my $aRow ( @{$oObj->{'$aArray'}} ) { print "@{$aRow}\n"; } Output: 0/0 1/0 2/0 3/0 4/0 5/0 6/0 7/0 8/0 9/0 10/0 11/0 12/0 13/0 14/0 15/0 ... 0/1 1/1 2/1 3/1 4/1 5/1 6/1 7/1 8/1 9/1 10/1 11/1 12/1 13/1 14/1 15/1 ... 0/2 1/2 2/2 3/2 4/2 5/2 6/2 7/2 8/2 9/2 10/2 11/2 12/2 13/2 14/2 15/2 ... 0/3 1/3 2/3 3/3 4/3 5/3 6/3 7/3 8/3 9/3 10/3 11/3 12/3 13/3 14/3 15/3 ... 0/4 1/4 2/4 3/4 4/4 5/4 6/4 7/4 8/4 9/4 10/4 11/4 12/4 13/4 14/4 15/4 ... 0/5 1/5 2/5 3/5 4/5 5/5 6/5 7/5 8/5 9/5 10/5 11/5 12/5 13/5 14/5 15/5 ... 0/6 1/6 2/6 3/6 4/6 5/6 6/6 7/6 8/6 9/6 10/6 11/6 12/6 13/6 14/6 15/6 ... 0/7 1/7 2/7 3/7 4/7 5/7 6/7 7/7 8/7 9/7 10/7 11/7 12/7 13/7 14/7 15/7 ... 0/8 1/8 2/8 3/8 4/8 5/8 6/8 7/8 8/8 9/8 10/8 11/8 12/8 13/8 14/8 15/8 ... 0/9 1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9 10/9 11/9 12/9 13/9 14/9 15/9 ... Rows and columns are swapped in the Perl array. Dict objServer.au3 (Examples\1) AutoIt to Perl\4) Dict obj\): Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict( "$iInt" ) = 123 $oDict( "$fFlt" ) = 123.456 $oDict( "$sStr" ) = "String" $oDataTransfer( "$oDict" ) = $oDict Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); print "${$oObj->{'$oDict'}}{'$iInt'}\n"; print "${$oObj->{'$oDict'}}{'$fFlt'}\n"; print "${$oObj->{'$oDict'}}{'$sStr'}\n"; Output: 123 123.456 String Data from Perl to AutoItSimple dataServer.au3 (Examples\2) Perl to AutoIt\1) Simple data\): #include "..\..\..\Includes\IRunningObjectTable.au3" Example() Func Example() Local $sDataTransfer = "DataTransfer" ROT_RegisterObject( Default, $sDataTransfer ) ; Default => Object = Dictionary object RunWait( @ComSpec & " /c " & "Perl Client.pl", "", @SW_HIDE ) Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object MsgBox( 0, "AutoIt/Perl integration", "$oDataTransfer( ""$iInt"" ) = " & $oDataTransfer( "$iInt" ) & @CRLF & _ "$oDataTransfer( ""$fFlt"" ) = " & $oDataTransfer( "$fFlt" ) & @CRLF & _ "$oDataTransfer( ""$sStr"" ) = " & $oDataTransfer( "$sStr" ) ) EndFunc Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); $oObj->{'$iInt'} = 123; $oObj->{'$fFlt'} = 123.456; $oObj->{'$sStr'} = "String"; Output: $oDataTransfer( "$iInt" ) = 123 $oDataTransfer( "$fFlt" ) = 123.456 $oDataTransfer( "$sStr" ) = String 1D arrayServer.au3 (Examples\2) Perl to AutoIt\2) 1D array\): #include "..\..\..\Includes\IRunningObjectTable.au3" #include <Array.au3> Example() Func Example() Local $sDataTransfer = "DataTransfer" ROT_RegisterObject( Default, $sDataTransfer ) ; Default => Object = Dictionary object RunWait( @ComSpec & " /c " & "Perl Client.pl", "", @SW_HIDE ) Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $aArray = $oDataTransfer( "$aArray" ) _ArrayDisplay( $aArray ) EndFunc Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); my @aArray = ( 123, 123.456, "String" ); $oObj->{'$aArray'} = \@aArray; Output: 123 123.456 String 2D arrayServer.au3 (Examples\2) Perl to AutoIt\3) 2D array\): #include "..\..\..\Includes\IRunningObjectTable.au3" #include <Array.au3> Example() Func Example() Local $sDataTransfer = "DataTransfer" ROT_RegisterObject( Default, $sDataTransfer ) ; Default => Object = Dictionary object RunWait( @ComSpec & " /c " & "Perl Client.pl", "", @SW_HIDE ) Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $aArray = $oDataTransfer( "$aArray" ) _ArrayDisplay( $aArray ) EndFunc Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); my @aArray; for( my $i = 0; $i < 10; $i++ ) { for( my $j = 0; $j < 1000; $j++ ) { $aArray[$i][$j] = $j . "/" . $i; } } $oObj->{'$aArray'} = \@aArray; Output: 0/0 0/1 0/2 0/3 0/4 0/5 0/6 0/7 0/8 0/9 1/0 1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 2/0 2/1 2/2 2/3 2/4 2/5 2/6 2/7 2/8 2/9 3/0 3/1 3/2 3/3 3/4 3/5 3/6 3/7 3/8 3/9 4/0 4/1 4/2 4/3 4/4 4/5 4/6 4/7 4/8 4/9 5/0 5/1 5/2 5/3 5/4 5/5 5/6 5/7 5/8 5/9 6/0 6/1 6/2 6/3 6/4 6/5 6/6 6/7 6/8 6/9 7/0 7/1 7/2 7/3 7/4 7/5 7/6 7/7 7/8 7/9 8/0 8/1 8/2 8/3 8/4 8/5 8/6 8/7 8/8 8/9 9/0 9/1 9/2 9/3 9/4 9/5 9/6 9/7 9/8 9/9 10/0 10/1 10/2 10/3 10/4 10/5 10/6 10/7 10/8 10/9 11/0 11/1 11/2 11/3 11/4 11/5 11/6 11/7 11/8 11/9 12/0 12/1 12/2 12/3 12/4 12/5 12/6 12/7 12/8 12/9 13/0 13/1 13/2 13/3 13/4 13/5 13/6 13/7 13/8 13/9 14/0 14/1 14/2 14/3 14/4 14/5 14/6 14/7 14/8 14/9 15/0 15/1 15/2 15/3 15/4 15/5 15/6 15/7 15/8 15/9 ... Dict objServer.au3 (Examples\2) Perl to AutoIt\4) Dict obj\): #include "..\..\..\Includes\IRunningObjectTable.au3" #include <Array.au3> Example() Func Example() Local $sDataTransfer = "DataTransfer" ROT_RegisterObject( Default, $sDataTransfer ) ; Default => Object = Dictionary object RunWait( @ComSpec & " /c " & "Perl Client.pl", "", @SW_HIDE ) Local $oDataTransfer = ObjGet( $sDataTransfer ) ; Dictionary object Local $aDict = $oDataTransfer( "$aDict" ) _ArrayDisplay( $aDict ) EndFunc Client.pl: use strict; use Win32::OLE; my $oObj = Win32::OLE->GetObject( "DataTransfer" ); my %oDict = ( '$iInt' => 123, '$fFlt' => 123.456, '$sStr' => "String" ); my @aDict = ( [ keys %oDict ], [ values %oDict ] ); $oObj->{'$aDict'} = \@aDict; Output: $iInt 123 $fFlt 123.456 $sStr String 7z-fileThe 7z-file contains source code for the UDF and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. AutoItAndPerl.7z Edited July 11, 2020 by LarsJ Danyfirex, Professor_Bernd, ptrex and 4 others 7 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now