Jump to content

Recommended Posts

Posted

@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

Posted

Hi @ptrex, if it possible to use your framework to add .Net control "MenuStrip" to AutoIt form.

I posted the question here:

Thank you in advance!

Posted (edited)

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
Posted (edited)

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
  • 3 weeks later...
Posted

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

  • 4 weeks later...
Posted

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

 

Posted (edited)
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
Posted

@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

Posted

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

Posted

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

 

  • 2 months later...
Posted

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

  • 4 months later...
Posted (edited)

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
  • 2 weeks later...
Posted

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 

  • 11 months later...
Posted

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

 

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
×
×
  • Create New...