Jump to content

create assembly in AuotIT


 Share

Recommended Posts

Is there anyway to create an assembly for AutoIT so that I can use that in Powershell or Dotnet supported languages like c#.

Like I want to use the functionality of _ArrayDisplay of AutoIT in C# by creating a assmbly/library and using that in the target language.

Link to comment
Share on other sites

With CLR.AU3 as given earlier there is an example: .NET GUI Form Controls & Events 2.au3 that shows how to catch events sent from the C# class

So the approach could be

1.  Build an exe with AutoIt which hosts the clr (by using clr.au3) and has the needed udf's of AutoIt in it

2. The C# assembly that is loaded by step 1 communicates with c# assembly / exe from step 3

3. The C# exe you made yourself

So although its not a dll created in step 1 in step 3 you could also start the exe of step 1 that was build with AutoIt3. 

Its an area nobody has been investigating but with WCF https://msdn.microsoft.com/en-us/library/ms731184.aspx

@Danyfirex is in this area the most knowledgable person I feel. Maybe he can add his thought on this.

Link to comment
Share on other sites

I'm really no interested in this kind of stuff.  ( But maybe I read later)

I would prefer don't spend so much time doing that. You probably want to do  something easier to avoid a lot of variable type casting.

Some suggestions.

1. Build your _arrayDisplay In each lenguage you want to use (I think would no be hard using PowerShell r C#)

2. Create a Commandline tool where you can pass maybe a file path with your data written from your PS or C# app and parse/show with arraydisplay.

 

 

Saludos

Link to comment
Share on other sites

Here is some simple code for a start. You can find it all in the zip below.

Run CSharpArrayDisplay.au3 or CSharpArrayDisplayEx.au3 from SciTE.

;#AutoIt3Wrapper_UseX64=y

#include <Array.au3>
#include <WinAPI.au3>
#include <WinAPIDlg.au3>

#include "Includes\CLR.au3"

ArrayDisplay()


Func ArrayDisplay()
  Local $sFile = _WinAPI_OpenFileDlg( "Open C# source file", @WorkingDir, "C# source file (*.cs)", 1, "", "", BitOR( $OFN_PATHMUSTEXIST, $OFN_FILEMUSTEXIST, $OFN_HIDEREADONLY ) )
  If @error Then Return ConsoleWrite( "Open file ERR" & @CRLF )
  ConsoleWrite( "Open file OK" & @CRLF )

  ; Get .NET Dll-references
  Local $aSrcArray, $aSplit, $sReferences = "System.dll"
  $aSrcArray = FileReadToArray( $sFile )
  For $i = 0 To UBound( $aSrcArray ) - 1
    If StringInStr( $aSrcArray[$i], "using " ) = 1 Then
      $aSplit = StringSplit( $aSrcArray[$i], "using ", 3 ) ; 3 =  $STR_ENTIRESPLIT + $STR_NOCOUNT
      $aSplit = StringSplit( $aSplit[1], ";", 2 )
      $aSplit[0] = StringStripWS( $aSplit[0], 7 ) ; 7 = $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES
      If $aSplit[0] = "System" Then ContinueLoop
      $sReferences &= " | " & $aSplit[0] & ".dll"
    ElseIf $aSrcArray[$i] = "class ArrayDisplayClass" Then
      ExitLoop
    EndIf
  Next
  If $i = UBound( $aSrcArray ) Then Return ConsoleWrite( "ArrayDisplayClass ERR" & @CRLF )
  ConsoleWrite( "ArrayDisplayClass OK" & @CRLF )

  Local $oAssembly, $oArrayDisplayClass, $aArray
  $oAssembly = _CLR_CompileCSharp( FileRead( $sFile ), $sReferences )
  If Not IsObj( $oAssembly ) Then Return ConsoleWrite( "$oAssembly ERR" & @CRLF )
  ConsoleWrite( "$oAssembly OK" & @CRLF )

  $oAssembly.CreateInstance( "ArrayDisplayClass", $oArrayDisplayClass )
  If Not IsObj( $oArrayDisplayClass ) Then Return ConsoleWrite( "$oArrayDisplayClass ERR" & @CRLF )
  ConsoleWrite( "$oArrayDisplayClass OK" & @CRLF )

  $aArray = $oArrayDisplayClass.ArrayDisplay()
  _ArrayDisplay( $aArray, "", "", 8 )
EndFunc

 

This is your own original C# code where you want to display an array. Note that the original source file is the a-version. Eg. IntArray-a.cs:

using System;

class MyClass
{
  public void MyMethod()
  {
    int[] MyArray = new [] { 1, 2, 3 };
  }
}

 

To display the array with _ArrayDisplay or _ArrayDisplayEx you have to add a few lines of code to the original source. Here the code is added to IntArray.cs:

using System;

class ArrayDisplayClass
{
  public int[] array;
  public int[] ArrayDisplay()
  {
    MyMethod();
    return array;
  }

  public void MyMethod()
  {
    int[] MyArray = new [] { 1, 2, 3 };

    array = MyArray;
  }
}

 

You can find a handful of examples in the zip file.

DisplayCSarray.7z

Edited by LarsJ
Link to comment
Share on other sites

  • 3 weeks later...

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