Jump to content

Using .NET libary with AutoIt, possible?


Recommended Posts

Hi!

Is there any way to use .NET DLL libraries with AutoIt? I happen to have one that'd have made my life easier, but DLLCall() returns an error: no functions with such name found. Searching and reading forums made me think that's not a fault of a library. I've used yashied's DLL Helper, but it didn't return any function names as well.

Thanks!

Link to comment
Share on other sites

I don't believe c# libraries have classic entry points like unmanaged dlls, so dllcall will not work.

I think I recall you have to make your dll com visible and use as an object, you should search it, there is something on the forum about it.

EDIT: .NET CLR is nowadays possible.

 

Edited by JohnOne

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

At the moment there is no way to access .NET libraries natively... 

2 Options left :

1. If this is a custom developed .NET libr. make it COM Visible as JohnOne indicated.

2. If you are looking for accessing .NET Class Libraries, you can use the PowerShell COM library as middleware...

    See my signature.

I am looking into how we could still achieve this to access it natively. But some highly skilled forum members has already let me know that this will not be an easy task....

It could be achieved by using the ObjCreateInterface and reading a lot on MSDN ...

It is NOW POSSIBLE TO ACCESS .NET Classes / THIRD PARTY ASSEMBLIES / POWERSHELL Cmdlets and MODULES

See here on 'how to' Examples

 

All members are welcome to contribute and help in any way they can ...

Rgds

ptrex

 

Edited by ptrex
Link to comment
Share on other sites

23-april-2017 initial au3 library posted in examples section over here

https://www.autoitscript.com/forum/topic/188158-net-common-language-runtime-clr-framework/

Introduction

In this whole tread posts 1-180 a lot of learning material which I try to summarize in this post 4. Around post 180 we had a working version ready for examples section to ask more help from others to enhance the UDF

a. Make use / enhance for more examples (the enduser of the udf --> see examples section in forum)

b. Host the CLR runtime in a better more documented way  (the technical side of the udf in this thread)

Reflection and related concepts
Important area in integrating interfaces, types, dynamic and related concepts all relate to reflection 

For starters

Summary post 1-180

Technical background

Some other relevant articles related to AutoIt and this CLR stuff

  • MSCorEE.DLL  and MSCORLIB.DLL by googling the internet

Books to read

Lengthy list of references used in the thread (clean / sort later in a logical order)

 

Edited by junkew
Overview of this thread till post 180
Link to comment
Share on other sites

For starters in COM

  1. https://www.codeproject.com/Articles/13601/COM-in-plain-C
  2. https://www.codeproject.com/Articles/13862/COM-in-plain-C-Part
  3. https://www.codeproject.com/Articles/14037/COM-in-plain-C-Part
  4. https://www.codeproject.com/Articles/14117/COM-in-plain-C-Part
  5. https://www.codeproject.com/Articles/14183/COM-in-plain-C-Part
  6. https://www.codeproject.com/Articles/14905/COM-in-plain-C-Part
  7. https://www.codeproject.com/Articles/15037/COM-in-plain-C-Part
  8. https://www.codeproject.com/Articles/17038/COM-in-plain-C-part
  •  

Studying this udf gives more understanding for defining and getting the interfaces and reflection / metadata from AutoIt

  1. https://www.autoitscript.com/forum/topic/114498-typelibinspector-oleview-was-yesterday/?page=2#comment-1048903
  2. https://www.autoitscript.com/forum/topic/112992-tliau3-type-information-on-com-objects-tlbinf-emulation/#comment-791089

AutoIt Object udf (AIO)

Excellent resource for studying on how to do more complex thing that AutoIt did not offer out of the box for creating objects. When learning a lot in this thread this AIO udf was also excellent area to see how Variant/COM  stuff is implemented in AutoIt by using oleaut32.dll 

https://www.autoitscript.com/forum/topic/110379-autoitobject-udf/#comment-775262
https://msdn.microsoft.com/en-us/library/windows/desktop/ms221673(v=vs.85).aspx

For me its a little unclear how AIO relates nowadays to objCreateInterface
 

; Declare the CLSID, IID and interface description for ITaskbarList.
    ; It is not necessary to describe the members of IUnknown.
    Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
    Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}"
    Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);"

    ; Create the object.
    Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList)

    ; Initialize the iTaskbarList object.
    $oTaskbarList.HrInit()

 

SafeArray udf

https://www.autoitscript.com/forum/topic/185883-accessing-autoit-variables/#comment-1335030

 

Edited by junkew
Link to comment
Share on other sites

headerFiles.7z:
  metahost.h
  mscoree-2.h (.NET v2)
  mscoree-4.h (.NET v4)
  mscorlib.tlh (_AppDomain interface)

 

Edited by LarsJ
Zip file removed
Link to comment
Share on other sites

Link to comment
Share on other sites

Not sure what the definition will be of using .NET in AutoIt

Maybe some examples on what people want to see working from AutoIt and how?

There are solutions like

Small dll's so you can use it without registering .NET classed as com

Register the .NET classes with regasm

but probably the requirement is to host the CLR

attention points

  • I remember something on passing byref and byvalue leads to issues in AutoIt and reading on .NET / COM interop thats frequently needed.

  • MSCorEE.DLL  (and related tlb) is unmanaged and should be possible to deal with from AutoIt (complexity similar to AIO)

  • MSCorLibl.DLL is managed code and contains all the classed people probably want to call directly/instantiate from ObjCreateInterface which I doubt is possible.

Probably smart to ask some of the AIO programmers their perspective on this if its possible at all.

My bet would be on building stuff in a .NET language and expose it with a REST JSON API interface.
asier and probably better nowadays to make API's in JSON or SOAP XML.

Link to comment
Share on other sites

Hi Junkew,

2 main reasons why to get this going :

1. Access to the .NET Class Libraries opens up a new world !

  • System
  • System.Collections
  • System.Data
  • System.Drawing
  • System.IO
  • System.Text
  • System.Threading
  • System.Timers
  • System.Web
  • System.Web.Services
  • System.Windows.Forms
  • System.Xml

2. Accessing custom build .Net libraries will be and extension to the current au3 functionality,

Some Examples (but there are a ton out there)

  • - JSonToXML libr.
  •  - XMLRPC Libr.
  • - .NETPDF libr.
  • - .NETOCR Libr
  • - WInSCP Libr.
  • - ...

Something like this are practical examples :

http://www.learnqtp.com/dotnetfactory-qtp-part1-basics/

 

 

Link to comment
Share on other sites

So far this is the status:When using the ObjCreateInterface :

$CLSID_CLRMetaHost = "{9280188D-0E8E-4867-B30C-7FA83884E8DE}"
$IID_ICLRDebugging = "{D28F3C5A-9634-4206-A509-477552EEFB10}"
$IID_ICLRDebuggingLibraryProvider = "{3151C08D-4D09-4F9B-8838-2880BF18FE51}"
$IID_ICLRMetaHost = "{D332DB9E-B9B3-4125-8207-A14884F53216}"
$IID_ICLRMetaHostPolicy = "{E2190695-77B2-492E-8E14-C4B3A7FDD593}"
$IID_ICLRProfiling = "{B349ABE3-B56F-4689-BFCD-76BF39D888EA}"
$IID_ICLRRuntimeInfo = "{BD39D1D2-BA2F-486A-89B0-B4B0CB466891}"
$IID_ICLRStrongName = "{9FD93CCF-3280-4391-B3A9-96E1CDE77C8D}"
$IID_IEnumUnknown = "{00000100-0000-0000-C000-000000000046}"
$IID_ISequentialStream = "{0C733A30-2A1C-11CE-ADE5-00AA0044773D}"
$IID_IStream = "{0000000C-0000-0000-C000-000000000046}"

$dtag = ""

$hRet = ObjCreateInterface($CLSID_CLRMetaHost, $IID_ICLRMetaHost , $dtag)

ConsoleWrite(IsObj($hRet) & @CRLF) 

No result it does not create an Object, because the mscoree.dll is not a COM object that is registered.

Using the Create Object direct access method  :

#AutoIt3Wrapper_UseX64=y

Global $CLSID_CLRMetaHost = "{9280188D-0E8E-4867-B30C-7FA83884E8DE}"
Global $IID_ICLRDebugging = "{D28F3C5A-9634-4206-A509-477552EEFB10}"
Global $IID_ICLRDebuggingLibraryProvider = "{3151C08D-4D09-4F9B-8838-2880BF18FE51}"
Global $IID_ICLRMetaHost = "{D332DB9E-B9B3-4125-8207-A14884F53216}"
Global $IID_ICLRMetaHostPolicy = "{E2190695-77B2-492E-8E14-C4B3A7FDD593}"
Global $IID_ICLRProfiling = "{B349ABE3-B56F-4689-BFCD-76BF39D888EA}"
Global $IID_ICLRRuntimeInfo = "{BD39D1D2-BA2F-486A-89B0-B4B0CB466891}"
Global $IID_ICLRStrongName = "{9FD93CCF-3280-4391-B3A9-96E1CDE77C8D}"
Global $IID_IEnumUnknown = "{00000100-0000-0000-C000-000000000046}"
Global $IID_ISequentialStream = "{0C733A30-2A1C-11CE-ADE5-00AA0044773D}"
Global $IID_IStream = "{0000000C-0000-0000-C000-000000000046}"

Global $hActiveX

; Load the server module
If @AutoItX64 Then
    $hActiveX  = DllOpen("C:\Windows\system32\mscoree.dll")
Else
    $hActiveX  = DllOpen("C:\Windows\system32\mscoree.dll")
EndIf
;MsgBox(0,"x64",@AutoItX64)

; Object identifiers
Global Const $sCLSID = "{9280188D-0E8E-4867-B30C-7FA83884E8DE}"
Global Const $sIID = "{D332DB9E-B9B3-4125-8207-A14884F53216}"
;Global Const $sIID = Default ; Or use keyword Default if you want to use the Default interface ID

; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc    ;==>_ErrFunc

; Create the hActiveX
Local $oNET = ObjCreate($sCLSID, $sIID, $hActiveX)

If $oNET = 0 Then MsgBox(16,"Error", "Could not create the object, Common problem ActiveX not registered.")

$oNET = ""
DllClose($hActiveX)

 No result either because the mscoree.dll is not an COM visible library...

In the C:\Windows\Microsoft.NET Framework folders you can find the mscoree.tlb type libr. file as well as the mscorlib.tlb one

If you open it using the trancexx TypeLib Viewer 

You can see all the CLSID / IID's

See file encloed : mscoree; // Common Language Runtime Execution Engine 2.4 Library

Some more developers expertise is needed here to point on...

rgds

ptrex

Common Language Runtime Execution Engine 2.4 Library.txt

Link to comment
Share on other sites

Using a wrapper around a wrapper of a wrapper:( .... I was able to get the CLRHost running ;)

Quote

FriendlyName           : DefaultDomain
Id                     : 1
ApplicationDescription : 
BaseDirectory          : C:\Program Files (x86)\AutoIt3\beta\
DynamicDirectory       : 
RelativeSearchPath     : 
SetupInformation       : System.AppDomainSetup
ShadowCopyFiles        : False

But this is not the way to go !

I hope that some of the devolopers reach out to give us a hand...

rgds

ptrex

Link to comment
Share on other sites

ptrex, A little comment to post 14. You must use CLRCreateInstance to get a pointer to ICLRMetaHost. And then use this pointer in ObjCreateInterface. But still a long way to go.

Link to comment
Share on other sites

Link to comment
Share on other sites

 

#AutoIt3Wrapper_UseX64 = y

#include <WinAPI.au3>

; Get handle of the loaded module
Local $hModule =  _WinAPI_LoadLibraryEx("C:\Windows\System32\mscoree.dll")

ConsoleWrite($hModule & @CRLF)

If $hModule Then
    Local $pFunction = _WinAPI_GetProcAddress($hModule, "CLRCreateInstance")
    ConsoleWrite("The address of the function is " & $pFunction & @CRLF & @CRLF)

    ; Do whatever here

EndIf

_WinAPI_FreeLibrary($hModule))

These are the functions in mscoree.dll

 

Quote

  Section contains the following exports for mscoree.dll

    00000000 characteristics
    57899178 time date stamp Sat Jul 16 03:44:24 2016
        0.00 version
          17 ordinal base
         126 number of functions
         123 number of names

    ordinal hint RVA      name

         38    0 000040C0 CLRCreateInstance
         39    1 0001B320 CallFunctionShim
         21    2 0001A600 CloseCtrs
         40    3 0001B490 ClrCreateManagedInstance
         41    4 0001B5A0 CoEEShutDownCOM
         42    5 0001B670 CoInitializeCor
         43    6 0001B760 CoInitializeEE
         44    7 0001B850 CoUninitializeCor
         45    8 0001B920 CoUninitializeEE
         25    9 0001A700 CollectCtrs
         46    A 0001BA00 CorBindToCurrentRuntime
         47    B 0001BB30 CorBindToRuntime
         48    C 0001BCA0 CorBindToRuntimeByCfg
         49    D 0001BE10 CorBindToRuntimeByPath
         50    E 0001BF10 CorBindToRuntimeByPathEx
         51    F 00003E50 CorBindToRuntimeEx
         52   10 0001C020 CorBindToRuntimeHost
         26   11 0001A820 CorDllMainWorker
         53   12 000042E0 CorExitProcess
         54   13 0001C1F0 CorGetSvc
         55   14 0001C2E0 CorIsLatestSvc
         56   15 0001C3E0 CorMarkThreadInThreadPool
         57   16 0001C4A0 CorTickleSvc
         58   17 00003640 CreateConfigStream
         59   18 0001C580 CreateDebuggingInterfaceFromVersion
         60   19 00021C50 CreateInterface
         61   1A 00004200 DllCanUnloadNow
         62   1B 00003FA0 DllGetClassObject
         63   1C 0001C690 DllRegisterServer
         64   1D 0001C770 DllUnregisterServer
         27   1E 0001AA10 EEDllGetClassObjectFromClass
         65   1F 0001C850 EEDllRegisterServer
         66   20 0001C940 EEDllUnregisterServer
         67   21 0001CA30 GetAssemblyMDImport
         68   22 00021CF0 GetCLRMetaHost
         69   23 0001CB40 GetCORRequiredVersion
         70   24 0001CC50 GetCORRootDirectory
         71   25 0001CD60 GetCORSystemDirectory
         72   26 0001CE70 GetCORVersion
         73   27 0001CF80 GetCompileInfo
         74   28 0001D060 GetFileVersion
         75   29 0001D190 GetHashFromAssemblyFile
         76   2A 0001D2E0 GetHashFromAssemblyFileW
         77   2B 0001D430 GetHashFromBlob
         78   2C 0001D5A0 GetHashFromFile
         79   2D 0001D6F0 GetHashFromFileW
         80   2E 0001D840 GetHashFromHandle
         81   2F 0001D990 GetHostConfigurationFile
         82   30 0001DA90 GetMetaDataInternalInterface
         83   31 0001DBE0 GetMetaDataInternalInterfaceFromPublic
         84   32 0001DCF0 GetMetaDataPublicInterfaceFromInternal
         85   33 0001DE00 GetPermissionRequests
         28   34 0001AB30 GetPrivateContextsPerfCounters
         29   35 000037F0 GetProcessExecutableHeap
         86   36 0001DFA0 GetRealProcAddress
         87   37 0001E0A0 GetRequestedRuntimeInfo
         88   38 0001E2E0 GetRequestedRuntimeVersion
         89   39 0001E410 GetRequestedRuntimeVersionForCLSID
         30   3A 0001AC10 GetStartupFlags
         31   3B 00003CD0 GetTargetForVTableEntry
         32   3C 00003BA0 GetTokenForVTableEntry
         90   3D 0001E560 GetVersionFromProcess
         91   3E 0001E690 GetXMLElement
         92   3F 0001E780 GetXMLElementAttribute
         93   40 0001E8A0 GetXMLObject
         94   41 0001E990 IEE
         17   42 0001ACF0 InitErrors
         19   43 0001ADD0 InitSSAutoEnterThread
         95   44 0001EA70 LoadLibraryShim
         96   45 0001EBA0 LoadLibraryWithPolicyShim
         22   46 0001ECD0 LoadStringRC
         97   47 0001EDF0 LoadStringRCEx
         98   48 0002A000 LockClrVersion
         33   49 0001AEB0 LogHelp_LogAssert
         34   4A 0001AFB0 LogHelp_NoGuiOnAssert
         35   4B 0001B090 LogHelp_TerminateOnAssert
         99   4C 0001F060 MetaDataGetDispenser
        100   4D 0001F170 ND_CopyObjDst
        101   4E 0001F290 ND_CopyObjSrc
        102   4F 0001F3B0 ND_RI2
        103   50 0001F4A0 ND_RI4
        104   51 0001F590 ND_RI8
        105   52 0001F680 ND_RU1
        106   53 0001F770 ND_WI2
        107   54 0001F870 ND_WI4
        108   55 0001F970 ND_WI8
        109   56 0001FA70 ND_WU1
         36   57 0001B160 OpenCtrs
         18   58 0001A5D0 PostError
         23   59 0001FC60 ReOpenMetaDataWithMemory
        110   5A 0001FD70 ReOpenMetaDataWithMemoryEx
        111   5B 0001FEA0 RunDll32ShimW
        112   5C 0001FFD0 RuntimeOSHandle
        113   5D 000200D0 RuntimeOpenImage
        114   5E 000201D0 RuntimeReleaseHandle
         37   5F 00003A70 SetTargetForVTableEntry
        115   60 000202C0 StrongNameCompareAssemblies
        116   61 000203D0 StrongNameErrorInfo
        117   62 000204B0 StrongNameFreeBuffer
        118   63 00020590 StrongNameGetBlob
        119   64 000206A0 StrongNameGetBlobFromImage
        120   65 000207C0 StrongNameGetPublicKey
        121   66 00020910 StrongNameHashSize
        122   67 00020A00 StrongNameKeyDelete
        123   68 00020AF0 StrongNameKeyGen
        124   69 00020C10 StrongNameKeyGenEx
        125   6A 00020D60 StrongNameKeyInstall
        126   6B 00020E70 StrongNameSignatureGeneration
        127   6C 00020FE0 StrongNameSignatureGenerationEx
        128   6D 00021180 StrongNameSignatureSize
        129   6E 00021290 StrongNameSignatureVerification
        130   6F 000213A0 StrongNameSignatureVerificationEx
        131   70 000214B0 StrongNameSignatureVerificationFromImage
        132   71 000215D0 StrongNameTokenFromAssembly
        133   72 000216E0 StrongNameTokenFromAssemblyEx
        134   73 00021830 StrongNameTokenFromPublicKey
        135   74 00021950 TranslateSecurityAttributes
         20   75 0001B250 UpdateError
        136   76 00003940 _CorDllMain
        137   77 000010A0 _CorExeMain
        138   78 00021C10 _CorExeMain2
        139   79 0000D1F0 _CorImageUnloading
        140   7A 0002B410 _CorValidateImage
         24      00003740 [NONAME]
        142      00003920 [NONAME]

Now what's next ...

Link to comment
Share on other sites

junkew, We don't need opinions or chit-chatting. We need code.

ptrex, I'll take a look at the code later this afternoon.

Link to comment
Share on other sites

  • Melba23 pinned and unpinned this topic

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