Jump to content

C# use of the dll, some idears for you.


 Share

Recommended Posts

When you are developing an app using AnyCPU you need a way to provide the correct 32 for 64 bit implementation of AutoItX3.

To do this I include both AutoItX3.dll and AutoItX3_x64.dll in the build but in AutoItX3Declarations I change all references to AutoItX3.dll to AutoItX3_targetted.dll

Then in MainForm.Load I copy the AutoItX3.dll orAutoItX3_x64.dll to a new file called AutoItX3_targetted.dll based on whether we are running in 32 bit or 64 bit environment. Here is the code.

//So that we can target 32 and 64bit system with AnyCPU we need to provide the correct AutoItX3 dll depending on platform.
            //We can't refference both of them.
            string ExecutingAssemblyPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string fullPath = "";
            string newFilePath = Path.Combine(ExecutingAssemblyPath, "AutoItX3_targetted.dll");
            if (IntPtr.Size == 4)
            {
                fullPath = Path.Combine(ExecutingAssemblyPath, "AutoItX3.dll");
            }
            else
            {
                fullPath = Path.Combine(ExecutingAssemblyPath, "AutoItX3_x64.dll");
            }
            if (System.IO.File.Exists(fullPath))
            {
                try
                {
                    System.IO.File.Copy(fullPath, newFilePath, true);
                }
                catch (Exception ex)
                {
                    Logger.WriteLog("AutoItX3_targetted.dll Creation Failure!", ex);
                    MessageBox.Show("AutoItX3_targetted.dll Creation Failure!rnApplicaction will Exit");
                    Application.Exit();
                }
            }

Regards,

John.

Link to comment
Share on other sites

  • 3 weeks later...

How can I do this in vb.net. (Use AutoItX without registering)

I think that if you convert the declarations to vb using a free online conversion tool then it will be no different from using it in C#.

Convert one declaration first to see if it works then you will know.

Please let us know how you get on.

Regards,

John.

Link to comment
Share on other sites

  • 1 year later...

If you want to avoid declaring StringBuilders in your main code and have it work more like the native AutoIt language you can add wrapper functions like this:

static public string AU3_WinGetText(string Title, string Text)
            {
                StringBuilder OutText = new StringBuilder(65536);
                AutoItX.AU3_WinGetText(Title, Text, OutText, OutText.Capacity);
                return OutText.ToString();
            }

So your usage becomes:

AutoItX.AU3_Run("notepad.exe", "", 1);
            AutoItX.AU3_WinWait("Untitled", "Something", 0);
            string WindowText = AutoItX.AU3_WinGetText("Untitled", "");
            Console.WriteLine(WindowText);
            AutoItX.AU3_ProcessClose("notepad.exe");
Link to comment
Share on other sites

  • 3 months later...
  • Administrators

Yeah. I'm going to supply the C# file that contains all the required DllImports to use AutoItX3.dll in C# (someone posted a complete one in this thread). I'm also going add some wrapper functions around those so in C# you'll essentially only need this:

using AutoIt;
...
AutoItX.WinWaitActive("Some window");
AutoItX.Send("hello");

Part of that work also means it's fairly easy for me to make it available to PowerShell as a Cmdlet. Cmdlets are just standalone functions you can add to powershell. And then the equivalent will be:

Import-Module .\AutoItX3_PS.dll

Wait-WinActive -Title "some window"
Send-Key -Key "Some keys"

This is cool because you don't need admin rights to "register" the DLL which was a slight barrier when using the COM version to a lot of companies. Also Microsoft mandate that all the software they produce these days must have a PowerShell interface so a lot of companies are investing in it. It's an easy but effective way to allow some of the more important AutoIt features in those environments.

Link to comment
Share on other sites

This is awesome, on the account I'm learning C#. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Ace.

I did use this threads code when I first tried AutoItX in C#.

Nice ideas, I'll have to look at powershell I don't even know what it is let alone know how to use it

Are we likely to see any more native functions in dll after update?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Administrators

Are we likely to see any more native functions in dll after update?

 

I imagine so. But I'm aiming it more at the sort of people who will use it in C# and PowerShell so I won't be added functions that are already very easy in those languages.

Link to comment
Share on other sites

Hi,

Please correct me if my under standing is wrong.

To use the Autolt in C# code I need to:

1. Make a class library AutoItX3Declarations.cs  that converts the native Autolt.dll to the .NET .dll (Question: since my machine is x64 and i use x64 compile i should import the x64 Autolt DLLs? or it doesnt really matter.)

2. Make another class library  'AutootxTest' which is a wrapper class for the classes in AutoItX3Declarations.cs

3. Make use of Methods of the wrapper class 'AutootxTest' in the c# code to access the native Autolt functions.

Link to comment
Share on other sites

  • Administrators

Check out the beta download, I've been doing a lot of work on providing the DLLimport class and wrappers. Unfortunately it's nowhere near finished yet as I've only recently starting fixing it up. But it will show you how I've been handling the x86/x64 thing and also adding c# friendly wrappers for the DLLImport functions.

Link to comment
Share on other sites

I was able to run a C# progam by c&p the  Autilt declration libray to my project as someone had suggested. It complains about some function as not being overloaded but the same overloaded functions work in the Autolt script editor. Anyways, this a good start.

Thank u all for providing helpful information in various posts.

Can't wait for the final DLL that can be directly used in the c#.

Link to comment
Share on other sites

  • 4 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...