Jump to content

.NET Common Language Runtime (CLR) Framework


Recommended Posts

@STetters

Using the WinSCP this way is the hard way ... Especially if you are not acquainted with .NET CLR.

I would recommend you to using either the traditional COM object approach :

 

 

Or the PowerShell .NET way.

I will see if I can make an example using the PS .NET way. But it will no be soon though ...

rgds

ptrex

Link to post
Share on other sites
  • Replies 86
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

WHAT : is .NET Common Language Runtime (CLR) Framework The Common Language Runtime (CLR) is a an Execution Environment . Common Language Runtime (CLR)'s main tasks are to convert the .NET Managed

Hi All, Added a Quick Reference eBook .NET CLR Framework for AutoIT.pdf to post 1. Which is a summary of all technical articles headlines we posted before, In order to give everyone interest

Hello. I was needing to zip and unzip some folders. So I found an easy way using CLR. here a simple example.   #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3"&

Thanks for your reply! @ptrex

The Ribbon is a nice option, but it doesn't have the MenuStrip like style I want. The MenuStrip is just a standard menu with better looking skin.

If is possible for you to show me an example of how to add a .Net Control to AutoIt GUI (not on WinForm).

Edited by wuruoyu
Link to post
Share on other sites

There is no way that I know to get .NET controls on AutoIT GUI's ?  Where did you pick this up ?

The examples shown here is the opposite ... AutoIT controls on WinForms.

Sorry if this was not clear.

According to me you are just looking for this ?

https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateMenu.htm 

 

Edited by ptrex
Link to post
Share on other sites
  • 3 weeks later...

As an idea: An interesting approach for this development would be to some how build a layer into scite using some special config file where known function calls can be switched (#UseCLR) to using CLR , for instance porting the simple Basic File I/O functions at first which is significant, then move on from there .., might get more interested and get the development speed to where it should be ..

Link to post
Share on other sites
  • 4 weeks later...

Hello. I was needing to zip and unzip some folders. So I found an easy way using CLR. here a simple example.

 

#include ".\Includes\CLR.au3"
#include ".\Includes\CLR Constants.au3"




Local $oAssembly = _CLR_LoadLibrary("System.IO.Compression.FileSystem")
ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)

Local $pAssemblyType = 0
$oAssembly.GetType_2("System.IO.Compression.ZipFile", $pAssemblyType)
ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF)

Local $oAssemblyType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType)
ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oAssemblyType) & @CRLF)

Local $sInputFolder="C:\Users\Raziel\Desktop\Files"
Local $sOutZipFile="C:\Users\Raziel\Desktop\Files.zip"

Local $aArray[] = [$sInputFolder,$sOutZipFile]
Local $Return = 0
;compress
$oAssemblyType.InvokeMember_3("CreateFromDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return)

Local $aArray[] = [$sOutZipFile,$sInputFolder & "-Extracted"]
;decompress
$oAssemblyType.InvokeMember_3("ExtractToDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return)

Exit

Saludos

 

Link to post
Share on other sites
17 minutes ago, Danyfirex said:

Hello. I was needing to zip and unzip some folders. So I found an easy way using CLR. here a simple example.

 

#include ".\Includes\CLR.au3"
#include ".\Includes\CLR Constants.au3"




Local $oAssembly = _CLR_LoadLibrary("System.IO.Compression.FileSystem")
ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)

Local $pAssemblyType = 0
$oAssembly.GetType_2("System.IO.Compression.ZipFile", $pAssemblyType)
ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF)

Local $oAssemblyType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType)
ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oAssemblyType) & @CRLF)

Local $sInputFolder="C:\Users\Raziel\Desktop\Files"
Local $sOutZipFile="C:\Users\Raziel\Desktop\Files.zip"

Local $aArray[] = [$sInputFolder,$sOutZipFile]
Local $Return = 0
;compress
$oAssemblyType.InvokeMember_3("CreateFromDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return)

Local $aArray[] = [$sOutZipFile,$sInputFolder & "-Extracted"]
;decompress
$oAssemblyType.InvokeMember_3("ExtractToDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return)

Exit

Saludos

 

About zip.au3 is the compression ratio better using your method above ?

 

Edited by antonioj84
Link to post
Share on other sites

@antonioj84 I really don't now you should take a look at System.IO.Compression.ZipFile in msdn.

I just need to zip a folder without take care of compression level.

 

Saludos

Link to post
Share on other sites

@antonioj84 , The compression will propably be the same since the ZIP.AU3 using the same windows build in classes. The ZIP.AU3 UDF use the traditional COM approach, while the .NET version use the CLR framework to access the classes. The main difference will be speed I guess... where the CLR might win over tradinational COM approach. You can do a simple test to compress using both approaches and compress speed and compression rate... easy to find out.

Link to post
Share on other sites

I think the approach above of .NET will be safer then the zip.au3 that is based on below logic where time / sleep function is important to function properly and script should not end before zipping is finished.

#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Zip all the files and folders in the desktop directory using the default parameters.
    Local $aFileList = _FileListToArray(@DesktopDir, Default, Default, True)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf

;Create empty zip file
    $str18zero=chr(0) & chr(0) & chr(0) & chr(0) & chr(0) & chr(0)
    $str18zero=$str18zero & $str18zero & $str18zero
    $EmptyZipFile="PK" & Chr(5) & Chr(6) & $str18zero
    $zipFileName=@tempdir & "\dummyfile.zip"
    
    $hZip=fileopen($zipFileName, $FO_OVERWRITE)
    filewrite($hZip,$emptyZipFile)
    fileclose($hZip)

;Add all the files  
    $oWsh = ObjCreate("Shell.Application")
    for $i=0 to ubound($aFileList)-1
        $oWsh.NameSpace($zipFileName).CopyHere($afilelist[$i] )
        sleep(150) ;Some weird speed issue
        ;consolewrite($afilelist[$i] & @CRLF)
    Next

    ; Display the results returned by _FileListToArray.
    ;_ArrayDisplay($aFileList, "$aFileList")
EndFunc   ;==>Example

 

Link to post
Share on other sites
  • 2 months later...

Found another nice one for Delphi example to call .NET classes that are not comvisible

Assm := Host.DefaultAppDomain.Load_2('NetAddr');
T := Assm.GetType_2('DelphiNET.NETAdder');
Obj := T.InvokeMember_3('ctor', BindingFlags_CreateInstance, nil, null, nil);
Params := VarArrayOf([2]);
WriteLn('2 + 3 = ' + IntToStr(T.InvokeMember_3('Add3', BindingFlags_InvokeMethod, nil, Obj, PSafeArray(VarArrayAsPSafeArray(Params)))));

https://stackoverflow.com/questions/2048540/hosting-clr-in-delphi-with-without-jcl-example

With the examples we already have above should be (whenever people are interested and have time ;-)) completing the stuff

Link to post
Share on other sites
  • 4 months later...

hi Junkew,

Thanks for the article ... very interesting indeed. 

But DotNet Core has some good and some bad news...

Dotnet Core is definitely the way forward replacing the full blown .Net environment.

The bad news is that some functionality has been dropped by MS ? :mad:

One of them is APPDOMAINS :

Quote

http://www.michael-whelan.net/replacing-appdomain-in-dotnet-core/

In the move to .Net Core, Microsoft decided to discontinue certain technologies because they were deemed to be problematic. AppDomain was one of those that did not make the cut. While AppDomains have been discontinued, some of their functionality is still being provided. 

What I like about .Net Core is definitely being cross platform functionality :) 

One code compiles to multiple OS's and Architectures !

I have been playing around with .Net Core a while and like that feature the most ...

https://audministrator.wordpress.com/2018/04/15/windows-core-iot-dotnet-core-on-a-raspberry-pi3/

https://audministrator.wordpress.com/2018/04/15/windows-core-iot-sqlite-on-a-raspberry-pi3/

https://audministrator.wordpress.com/2018/04/20/windows-core-iot-asp-dotnet-core-razor-pages-on-a-raspberry-pi3/

https://audministrator.wordpress.com/2017/01/23/windows-core-iot-accessing-a-dotnet-dll-assembly-on-a-raspberry-pi3/

...

Edited by ptrex
Link to post
Share on other sites
  • 2 weeks later...

Hi All,

PowersShell 6.0 Core has been released for .Net Core +2.0 SDK

https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-60?view=powershell-6 

TESTED : AutoItX PowerShell Module on Powershell Core 6 Preview on Windows 10

https://audministrator.wordpress.com/2018/07/02/powershell-core-running-on-windows-iot-using-a-rpi3/ 

The module runs as well on a RPI3 ARM architecture,

But the functionality au3 functions don't work of course. Because the AutoIT dll's are compiled for an Intel architecture and not for an ARM architecture.

Anyhow this shows the difference between running a PowerShell host in .Net Framework and .Net Core Framework :

Comparison - Hosting Windows PowerShell vs. Hosting PowerShell Core

https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell#net-core-sample-application 

Link to post
Share on other sites
  • 11 months later...

Hi All,

It's been a while since someone posted something in the .NET CLR post ...

Here is an example that loads a fully functional Report Designer .NET Assembly using  CLR Library

Features :
• Easy to use (WYSIWYG)
• Compartible with .net 2.0 and above
• Easy to integrate in an application
• Supports most DBMS (SQL server, SQL Express, MYSQL, MS Access & ODBC)
• Simple expressions
• Grouping and sorting
• 1D Barcodes (Code 39, 128 and EAN 13), QR (requires qr library)
 

Result :

image-10.png

CLR using the PS Automation Assembly :

#AutoIt3Wrapper_UseX64=n

#include "CLR.Au3"

$str = _Base64Decode("JFJ1bnNwYWNlID0gW3J1bnNwYWNlZmFjdG9yeV06OkNyZWF0ZVJ1bnNwYWNlKCkNCg0KJFJ1bnNwYWNlLkFwYXJ0bWVudFN0YXRlID0gIlNUQSIgIyBDaGFuZ2UgaGVyZSAhDQokUnVuc3BhY2UuVGhyZWFkT3B0aW9ucyA9ICJSZXVzZVRocmVhZCINCiRob3N0LlJ1bnNwYWNlLlRocmVhZE9wdGlvbnMudmFsdWVfXw0KJFJ1bnNwYWNlLlJ1bnNwYWNlU3RhdGVJbmZvDQoNCiRQb3dlclNoZWxsID0gW3Bvd2Vyc2hlbGxdOjpDcmVhdGUoKQ0KDQokUG93ZXJTaGVsbC5ydW5zcGFjZSA9ICRSdW5zcGFjZQ0KDQokUnVuc3BhY2UuT3BlbigpDQoNCiRzdHJpbmcgPSB7IA0KQWRkLVR5cGUgLUFzc2VtYmx5TmFtZSBTeXN0ZW0uV2luZG93cy5Gb3Jtcw0KQWRkLVR5cGUgLVBhdGggIkM6XF9cQXBwc1xfUG93ZXJTaGVsbFxfR1VJIEZvcm1zXC5ORVQgUmVwb3J0IEJ1aWxkZXJcUmVwb3J0RGVzaWduZXI1LjEuMC43LmRsbCINCkFkZC1UeXBlIC1QYXRoICJDOlxfXEFwcHNcX1Bvd2VyU2hlbGxcX0dVSSBGb3Jtc1wuTkVUIFJlcG9ydCBCdWlsZGVyXFFSQ29kZXIuZGxsIg0KQWRkLVR5cGUgLVBhdGggIkM6XF9cQXBwc1xfUG93ZXJTaGVsbFxfR1VJIEZvcm1zXC5ORVQgUmVwb3J0IEJ1aWxkZXJcU3lzdGVtLkRhdGEuU1FMaXRlLmRsbCINCkFkZC1UeXBlIC1QYXRoICJDOlxfXEFwcHNcX1Bvd2VyU2hlbGxcX0dVSSBGb3Jtc1wuTkVUIFJlcG9ydCBCdWlsZGVyXE15U3FsLkRhdGEuZGxsIg0KDQokcmQgPSBOZXctT2JqZWN0IFJlcG9ydERlc2lnbmVyNS5EZXNpZ25lcg0KDQokcmQuUHJvZHVjdFZlcnNpb24NCg0KJHJkID0gTmV3LU9iamVjdCBSZXBvcnREZXNpZ25lcjUuRGVzaWduZXINCiRyZC5TaG93RGlhbG9nKCkNCiRyZC5TaG93UHJvcGVydHkoKQ0KJHJkLlNob3dSZXBvcnRUcmVlKCkNCn0NCg0KW3ZvaWRdJFBvd2VyU2hlbGwuQWRkU2NyaXB0KCRzdHJpbmcpDQoNCiRQb3dlclNoZWxsLkludm9rZSgpIA==")

_Run_PSHost_Script(BinaryToString($str,1)) ; 1 = Ansi, 2 = UTF16 Little Endian


Func _Run_PSHost_Script($PSScript)
    Local $oAssembly = _CLR_LoadLibrary("System.Management.Automation")
    ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)

    ; Create Object
    Local $pAssemblyType = 0
    $oAssembly.GetType_2("System.Management.Automation.PowerShell", $pAssemblyType)
    ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF)

    Local $oActivatorType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType)
    ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oActivatorType) & @TAB & @CRLF)

    ; Create Object
    Local $pObjectPS = 0
    $oActivatorType.InvokeMember_3("Create", 0x158, 0, 0, 0, $pObjectPS)
    ConsoleWrite("IsObject: " & IsObj($pObjectPS) & @TAB & "$pObject: " & ObjName($pObjectPS) & @CRLF)


    $pObjectPS.AddScript($PSScript) ; Add Script here


    $objAsync = $pObjectPS.BeginInvoke ; (2); ($oActivatorType,$oActivatorType)

    While $objAsync.IsCompleted = False

        ContinueLoop
    WEnd
        ConsoleWrite("Completed : " & $objAsync.IsCompleted & @CRLF)

    $objPsCollection = $pObjectPS.EndInvoke($objAsync)

EndFunc


Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int;int;int")
    Local $dwFlags = 1 ; Base64, no headers

    DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", StringLen($input_string), _
            "int", $dwFlags, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", DllStructGetPtr($struct, 2), _
            "ptr", DllStructGetPtr($struct, 3))

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", StringLen($input_string), _
            "int", $dwFlags, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", DllStructGetPtr($struct, 2), _
            "ptr", DllStructGetPtr($struct, 3))

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

 

Downloads :

RB Assembly here :

https://sourceforge.net/projects/report-builder/

Prequisites :

Reference 2 additional Assemblies for this version :

1. QRCoder.dll version 1.3.5

2. SQLIte.dll version 1.0.109

Many thanks for the developer of the Report Builder .NET Assembly !

 

Enjoy!

ptrex

 

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.

  • Similar Content

    • By Skeletor
      Hi All,
      So I was searching through the internet and found a plethora of information to learn C#. 
      However, some are way below par and does not explain very well. 

      So, anyone can suggest a proper website or eBook or video course explaining C#?
       
      I've learnt AutoIt (still I'm learning it) by making small programs, reading the forums, going through the F1 guide (huge help, seriously this helps alot) and reading the Wiki.
      Any direction would be appreciated, just not off the edge of a cliff.. 
    • By mLipok
      I have a project in mind that I would like to share.
      I would like to create example windows with standard elements like ComboBox, ListView, some Button, some text, some edit field.

      Nothing special just simple Window.Net form that can be created with this following UDF:
      or this one:
       
      The main idea is to easily provide possible modifications to the "Testing GUI Window", and no need for any other tool than the AutoIt + SciTE kit.

      Such "Testing GUI Window" will be very useful later on topic/threads/projects like:

      As I am not very familiar with NetFramework, I would like to ask for help with this project.
      Thanks in advance for any help.
      @mLipok
       
       
       
    • By buymeapc
      Hello,
      I was looking for a way to use the CLR functions to check a SQL 2016 database state, but I've been unable to find an example that I can get to work. Any help would be appreciated. Here's what I have, which always errors when I try to set the connection string and I'm not sure why. Thanks!
      #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" JustATest() Func JustATest() Local $oAssembly = _CLR_LoadLibrary("System.Data") ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $oSQLConn = _CLR_CreateObject($oAssembly, "System.Data.SqlClient.SqlConnection") ConsoleWrite("$oSQLConn: " & IsObj($oSQLConn) & @CRLF) $oSQLConn.ConnectionString = "Server=serverip;Database=dbname;UID=user;PWD=aaaa;" $oSQLConn.Open EndFunc Edit: I am using ptrex's CLR UDF from here:
    • By Earthshine
      This baby can do almost any language! I found Gleany on this site and set it up on a fresh win10 install. all i would need to do to make it build an exe of the search files app we discovered is the .NET Target Framework download to build 100 % but the exe works and generates! You also need to add the path the the version of csc.exe that you want to run. MSBuild is part of .NET and can read your .csproj file.
      YOU can develop .NET OR C/C++ on this baby!
      Super lightweight (fit for crappy laptops), and you can use any dev compilers you wish, Ming, MS, etc, whatever.
      To use the build, you need to open the csproj file, else, to check your syntax it can compile individual files as well. The warning are because I do not have the .NET 4.6 Targeting Pack installed... LOL, and I could get rid of the Core warning, yes, I did not want to build a .NET Core.dll I wanted a live x64 exe! Told you MSBUILD could handle .CSPROJ, .VBPROJ, and all others Microsoft. Don't let Visual Code or Visual Studio slow you down, although, this works with Visual Code as well but there is only debugging in CORE.DLL projects

      ListFiles Example.zip
       

    • By breakbadsp
      AutoIT AU3info doeas not detect all gui objects uniquely for .NET GUIs developed in C#.
      this is not working now i am using COM windows approach for this, But its very difficult.
      Please let me know if anyone has done it before.
×
×
  • Create New...