Jump to content
Sign in to follow this  
mjolnirmarkiv

Using .NET libary with AutoIt, possible?

Recommended Posts

@Junkew, 

Indeed your example was working from the beginning .... that's why I included it is the distribution Examples ;)

Thanks to Danyfirex again :graduated:  we can extend your post 91, with his example.

Giving this result (a mix between yours and his)

#include ".\Includes\CLR.au3"

Example()

Func Example()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)

    Local $pType
    $oAssembly.GetType_2("System.Activator",$pType)
    ConsoleWrite("!$pType: " & ptr($pType) & @CRLF)

    Local $oType = ObjCreateInterface($pType, $sIID_IType, $sTag_IType)
    ConsoleWrite("IsObj( $oType ) = " & IsObj($oType) & @CRLF)
    ConsoleWrite(@CRLF)

    Local $aText[] = ["mscorlib", "System.Collections.Stack"]
    Local $pObject = 0
    $oType.InvokeMember_3("CreateInstance", 0x158, 0, 0, CreateSafeArray($aText), $pObject)
    ConsoleWrite("IsObject: " & IsObj($pObject) & @TAB & "$pObject: " & $pObject & @CRLF)

    Local $oStack = $pObject.Unwrap()
    ConsoleWrite("!$oStack: " & IsObj($oStack) & @CRLF)
    $oStack.Push("Bye Bye...")
    $oStack.Push("I Love AutoIt...")
    $oStack.Push("AutoIt Rocks...")

    For $i = 0 To $oStack.Count() - 1
        MsgBox(0, "Stack Example", $oStack.Pop())
    Next

EndFunc   ;==>Example

Nevertheless the example of Danyfirex is a bit more clear to follow, so I will replace the provious example in the distribution with his version...

Next objective is that we get some more examples running ... hopefully this was the only missing link in the puzzle ...

I am still looking in the the 'Reflection' part for the time being, but a but short of time to dig into this completely at the moment...

Anyhow this is again a good step forward in helping us understand how the CLR tends to work... keeps us all fascinating for some time (I hope ...)

 


Share this post


Link to post
Share on other sites

Hello. I've still not read about System.Activator to create System.Int32 types etc. Maybe I'll do later. Would be fine if some of you share a example made in anothe programming lenguage.

Here is the ClipGet Example Fixed.

#include ".\Includes\CLR.au3"
Example2()
Func Example2()

    Local  $sAutoItX3AssemblyPath = RegRead("HKLM\SOFTWARE" & (@AutoItX64 ? "\Wow6432Node" : "") & "\AutoIt v3\AutoIt", "InstallDir") & "\AutoItX\AutoItX3.Assembly.dll"
    ConsoleWrite("AutoItX3.Assembly.dll Path: " & $sAutoItX3AssemblyPath & @CRLF)

    Local $oAssembly = _CLR_LoadLibrary($sAutoItX3AssemblyPath) ; Equals [Reflection.Assembly]::Loadfile()
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

    Local $pAssemblyType = 0
    $oAssembly.GetType_2("AutoIt.AutoItX", $pAssemblyType)
    ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF)

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

    Local $aText[] = ["We Love AutoIt !!"]
    Local $sClipBoardText = ""
;~     $oAssemblyType.InvokeMember_3("", 0x158, 0, 0, 0, 0)
    $oAssemblyType.InvokeMember_3("ClipPut", 0x158, 0, 0, CreateSafeArray($aText), 0)
    ConsoleWrite("Clipboard Data: " & ClipGet() & @CRLF)
    MsgBox(0,"[AutoIt.AutoItX]::ClipPut" , "Clipboard Data: " & ClipGet())
    sleep (1000)
    ClipPut("AutoIt Rocks!!!")
    Local $aText[] = [0]
    $oAssemblyType.InvokeMember_3("ClipGet", 0x158, 0, 0, CreateSafeArray($aText), $sClipBoardText)
    ConsoleWrite("Clipboard Data: " & $sClipBoardText & @CRLF)
    MsgBox(0,"[AutoIt.AutoItX]::ClipPut" , "New Clipboard Data: " & $sClipBoardText)

EndFunc   ;==>Example

Saludos

Share this post


Link to post
Share on other sites

Hi Again,

You are so unbelievable !! Thanks for looking into this... I will test it and update the examples released ...

You asked for it, so you get it ... ;)

This is the link to the other example in another language C#. 

http://www.windowsdevcenter.com/pub/a/dotnet/excerpt/prog_csharp_ch18/?page=6

It's not that I am a mathematician but it seems a good learning curve in .NET.

These so trivial functions are so hard to retrieve and therefor a good learning curve ?!

Getting the Activator System.Int32 running is not a problem ... 

Example1()

Func Example1()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

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

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

    ; Create a System.Int32 or System.Double Object
    Local $aText[] = ["mscorlib", "System.Int32"] ; "System.Double"
    Local $pObject = 0
    $oActivatorType.InvokeMember_3("CreateInstance", 0x158, 0, 0, CreateSafeArray($aText), $pObject)
    ConsoleWrite("IsObject: " & IsObj($pObject) & @TAB & "$pObject: " & $pObject & @CRLF)

    ; Create a System.Math Object
    Local $theMathType1 = 0
    $oAssembly.GetType_2("System.Math", $theMathType1)
    ConsoleWrite("$theMathType1 = " & Ptr($theMathType1) & @CRLF)

    Local $oMathType = ObjCreateInterface($theMathType1, $sIID_IType, $sTag_IType)
    ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oMathType) & @TAB & @CRLF)
    
    ; More code here need help ....
EndFunc

It seems out of the C# Example that we first need to have GetMethod_2 running ?

Which we have not used before If I remember well...

"GetMethod_2 hresult(bstr;ptr;ptr);

Next it should look something like this ... but no result for me

Example1()

Func Example1()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

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

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

    ; Create a System.Int32 or System.Double Object
    Local $aText[] = ["mscorlib", "System.Double"] ; "System.Double"
    Local $pObject = 0
    $oActivatorType.InvokeMember_3("CreateInstance", 0x158, 0, 0, CreateSafeArray($aText), $pObject)
    ConsoleWrite("IsObject: " & IsObj($pObject) & @TAB & "$pObject: " & $pObject & @CRLF)

    ; Create a System.Math Object
    Local $theMathType1 = 0
    $oAssembly.GetType_2("System.Math", $theMathType1)
    ConsoleWrite("$theMathType1 = " & Ptr($theMathType1) & @CRLF)

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

    ; Fill an array with the actual parameters
    Local $aArray[] = [45] ;
    CreateSafeArray($aArray)

    Local $pMath = $oMathType.GetMethod_2("COS", CreateSafeArray($aArray), $pObject) ; <=== NOT WORKING
    ConsoleWrite($pMath & @CRLF)

EndFunc   ;==>Example

I did something wrong with the SafeArray because I need a ptr returned, this is not my strong side...

And next the GetMethod_2 is just a wild guess from my side too, base on the C# example translation...

I hope I am not too far off ...

 


Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

optrex I was expecting a C/C++ example because NET Lenguages does some casting I dont want to look inside. 

 

Saludos

Share this post


Link to post
Share on other sites

@Danyfirex

For examples 

Day2day i work a lot with hp uft and part of that is dotnetfactory

If you search dotnetfactory you find many examples that could be usefull in AutoIt although i have not found yet a killing stunnishing example

http://codoid.com/capturing-screen-region/

https://qtautomation.blogspot.nl/2013/09/dot-net-factory-article-1.html

I am reading on the dynamic keyword and feel somehow with that you can create objects on the fly including dot syntax. That would be real fun in AutoIt.

 

Share this post


Link to post
Share on other sites

Hello. I Just got some free time and I played a little bit with the NET stuffs, so I got another nice example... Run a NET Exe From Memory.

;~ #AutoIt3Wrapper_UseX64=y
#include <Memory.au3>
#include "SafeArray.au3"
#include "Variant.au3"

Opt("MustDeclareVars", 1)

Global Const $S_OK = 0

Global Const $sTag_CLRMetaHost = _
        "GetRuntime hresult(wstr;struct*;ptr);" & _
        "GetVersionFromFile hresult(ptr;ptr;ptr);" & _
        "EnumerateInstalledRuntimes hresult(ptr);" & _
        "EnumerateLoadedRuntimes hresult(ptr;ptr);" & _
        "RequestRuntimeLoadedNotification hresult(ptr,ptr,ptr):" & _
        "QueryLegacyV2RuntimeBinding hresult(ptr;ptr);" & _
        "ExitProcess hresult(int);"

Global Const $sTagCLRRuntimeInfo = "GetVersionString hresult(ptr;ptr);" & _
        "GetRuntimeDirectory hresult(ptr;ptr);" & _
        "IsLoaded hresult(ptr;ptr);" & _
        "LoadErrorString hresult(ptr;ptr;ptr;ptr);" & _
        "LoadLibrary hresult(ptr;ptr);" & _
        "GetProcAddress hresult(ptr;ptr);" & _
        "GetInterface hresult(ptr;ptr;ptr);" & _
        "IsLoadable hresult(Bool*);" & _
        "SetDefaultStartupFlags hresult(ptr;ptr);" & _
        "GetDefaultStartupFlags hresult(ptr;ptr;ptr);" & _
        "BindAsLegacyV2Runtime hresult();" & _
        "IsStarted hresult(ptr;ptr);"

Global Const $sTag_CLRRuntimeInfo = _
        "GetVersionString hresult(ptr;ptr);" & _
        "GetRuntimeDirectory hresult(ptr;ptr);" & _
        "IsLoaded hresult(ptr;ptr);" & _
        "LoadErrorString hresult(ptr;ptr;ptr;ptr);" & _
        "LoadLibrary hresult(ptr;ptr);" & _
        "GetProcAddress hresult(ptr;ptr);" & _
        "GetInterface hresult(ptr;ptr;ptr);" & _
        "IsLoadable hresult(Bool*);" & _
        "SetDefaultStartupFlags hresult(ptr;ptr);" & _
        "GetDefaultStartupFlags hresult(ptr;ptr;ptr);" & _
        "BindAsLegacyV2Runtime hresult();" & _
        "IsStarted hresult(ptr;ptr);"

Global Const $sTag_CLRRuntimeHost = _
        "Start hresult();" & _
        "Stop hresult();" & _
        "SetHostControl hresult(ptr);" & _
        "GetCLRControl hresult(ptr*);" & _
        "UnloadAppDomain hresult(ptr;ptr);" & _
        "ExecuteInAppDomain hresult(ptr;ptr;ptr);" & _
        "GetCurrentAppDomainId hresult(ptr);" & _
        "ExecuteApplication hresult(ptr;ptr;ptr;ptr;ptr;ptr);" & _
        "ExecuteInDefaultAppDomain hresult(wstr;wstr;wstr;wstr;ptr*);"

Global Const $sTagEnumUnknown = "Next hresult(ulong;ptr*;ulong); Skip hresult(ptr); Reset hresult(); Clone hresult(ptr);"
Global Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
Global Const $sTag_IDispatch = _
        "GetTypeInfoCount hresult(dword*);" & _ ; Retrieves the number of type information interfaces that an object provides (either 0 or 1).
        "GetTypeInfo hresult(dword;dword;ptr*);" & _ ; Gets the type information for an object.
        "GetIDsOfNames hresult(ptr;ptr;dword;dword;ptr);" & _ ; Maps a single member and an optional set of argument names to a corresponding set of integer DISPIDs, which can be used on subsequent calls to Invoke.
        "Invoke hresult(dword;ptr;dword;word;ptr;ptr;ptr;ptr);" ; Provides access to properties and methods exposed by an object.

Global Const $sIID_IAssembly = "{17156360-2F1A-384A-BC52-FDE93C215C5B}"
Global Const $sTag_IAssembly = _
        $sTag_IDispatch & _
        "get_ToString hresult(bstr*);" & _ ; Replaced "get_ToString hresult();" & _
        "Equals hresult();" & _
        "GetHashCode hresult();" & _
        "GetType hresult(ptr*);" & _
        "get_CodeBase hresult();" & _
        "get_EscapedCodeBase hresult();" & _
        "GetName hresult();" & _
        "GetName_2 hresult();" & _
        "get_FullName hresult(bstr*);" & _ ; Replaced "get_FullName hresult();" & _
        "get_EntryPoint hresult(ptr*);" & _
        "GetType_2 ptr(bstr);" & _
        "GetType_3 hresult();" & _
        "GetExportedTypes hresult();" & _
        "GetTypes hresult(ptr*);" & _ ; Replaced "GetTypes hresult();" & _
        "GetManifestResourceStream hresult();" & _
        "GetManifestResourceStream_2 hresult();" & _
        "GetFile hresult();" & _
        "GetFiles hresult();" & _
        "GetFiles_2 hresult();" & _
        "GetManifestResourceNames hresult();" & _
        "GetManifestResourceInfo hresult();" & _
        "get_Location hresult();" & _
        "get_Evidence hresult();" & _
        "GetCustomAttributes hresult();" & _
        "GetCustomAttributes_2 hresult();" & _
        "IsDefined hresult();" & _
        "GetObjectData hresult();" & _
        "add_ModuleResolve hresult();" & _
        "remove_ModuleResolve hresult();" & _
        "GetType_4 hresult();" & _
        "GetSatelliteAssembly hresult();" & _
        "GetSatelliteAssembly_2 hresult();" & _
        "LoadModule hresult();" & _
        "LoadModule_2 hresult();" & _
        "CreateInstance hresult(bstr;variant*);" & _
        "CreateInstance_2 hresult(bstr;bool;variant*);" & _
        "CreateInstance_3 hresult(bstr;bool;int;ptr;ptr;ptr;ptr;variant*);" & _
        "GetLoadedModules hresult();" & _
        "GetLoadedModules_2 hresult();" & _
        "GetModules hresult();" & _
        "GetModules_2 hresult();" & _
        "GetModule hresult();" & _
        "GetReferencedAssemblies hresult();" & _
        "get_GlobalAssemblyCache hresult();"

Global Const $sIID_IType = "{BCA8B44D-AAD6-3A86-8AB7-03349F4F2DA2}"
Global Const $sTag_IType = _
        $sTag_IDispatch & _
        "get_ToString hresult(bstr*);" & _
        "Equals hresult(variant;short*);" & _
        "GetHashCode hresult(int*);" & _
        "GetType hresult(ptr);" & _
        "get_MemberType hresult(ptr);" & _
        "get_name hresult(bstr*);" & _
        "get_DeclaringType hresult(ptr);" & _
        "get_ReflectedType hresult(ptr);" & _
        "GetCustomAttributes hresult(ptr;short;ptr);" & _
        "GetCustomAttributes_2 hresult(short;ptr);" & _
        "IsDefined hresult(ptr;short;short*);" & _
        "get_Guid hresult(ptr);" & _
        "get_Module hresult(ptr);" & _
        "get_Assembly hresult(ptr*);" & _
        "get_TypeHandle hresult(ptr);" & _
        "get_FullName hresult(bstr*);" & _
        "get_Namespace hresult(bstr*);" & _
        "get_AssemblyQualifiedName hresult(bstr*);" & _
        "GetArrayRank hresult(int*);" & _
        "get_BaseType hresult(ptr);" & _
        "GetConstructors hresult(ptr;ptr);" & _
        "GetInterface hresult(bstr;short;ptr);" & _
        "GetInterfaces hresult(ptr);" & _
        "FindInterfaces hresult(ptr;variant;ptr);" & _
        "GetEvent hresult(bstr;ptr;ptr);" & _
        "GetEvents hresult(ptr);" & _
        "GetEvents_2 hresult(int;ptr);" & _
        "GetNestedTypes hresult(int;ptr);" & _
        "GetNestedType hresult(bstr;ptr;ptr);" & _
        "GetMember hresult(bstr;ptr;ptr;ptr);" & _
        "GetDefaultMembers hresult(ptr);" & _
        "FindMembers hresult(ptr;ptr;ptr;variant;ptr);" & _
        "GetElementType hresult(ptr);" & _
        "IsSubclassOf hresult(ptr;short*);" & _
        "IsInstanceOfType hresult(variant;short*);" & _
        "IsAssignableFrom hresult(ptr;short*);" & _
        "GetInterfaceMap hresult(ptr;ptr);" & _
        "GetMethod hresult(bstr;ptr;ptr;ptr;ptr;ptr);" & _
        "GetMethod_2 hresult(bstr;ptr;ptr);" & _
        "GetMethods hresult(int;ptr);" & _
        "GetField hresult(bstr;ptr;ptr);" & _
        "GetFields hresult(int;ptr);" & _
        "GetProperty hresult(bstr;ptr;ptr);" & _
        "GetProperty_2 hresult(bstr;ptr;ptr;ptr;ptr;ptr;ptr);" & _
        "GetProperties hresult(ptr;ptr);" & _
        "GetMember_2 hresult(bstr;ptr;ptr);" & _
        "GetMembers hresult(int;ptr);" & _
        "InvokeMember hresult(bstr;ptr;ptr;variant;ptr;ptr;ptr;ptr;variant*);" & _
        "get_UnderlyingSystemType hresult(ptr);" & _
        "InvokeMember_2 hresult(bstr;int;ptr;variant;ptr;ptr;variant*);" & _
        "InvokeMember_3 hresult(bstr;int;ptr;variant;ptr;variant*);" & _
        "GetConstructor hresult(ptr;ptr;ptr;ptr;ptr;ptr);" & _
        "GetConstructor_2 hresult(ptr;ptr;ptr;ptr;ptr);" & _
        "GetConstructor_3 hresult(ptr;ptr);" & _
        "GetConstructors_2 hresult(ptr);" & _
        "get_TypeInitializer hresult(ptr);" & _
        "GetMethod_3 hresult(bstr;ptr;ptr;ptr;ptr;ptr;ptr);" & _
        "GetMethod_4 hresult(bstr;ptr;ptr;ptr);" & _
        "GetMethod_5 hresult(bstr;ptr;ptr);" & _
        "GetMethod_6 hresult(bstr;ptr);" & _
        "GetMethods_2 hresult(ptr);" & _
        "GetField_2 hresult(bstr;ptr);" & _
        "GetFields_2 hresult(ptr);" & _
        "GetInterface_2 hresult(bstr;ptr);" & _
        "GetEvent_2 hresult(bstr;ptr);" & _
        "GetProperty_3 hresult(bstr;ptr;ptr;ptr;ptr);" & _
        "GetProperty_4 hresult(bstr;ptr;ptr;ptr);" & _
        "GetProperty_5 hresult(bstr;ptr;ptr);" & _
        "GetProperty_6 hresult(bstr;ptr;ptr);" & _
        "GetProperty_7 hresult(bstr;ptr);" & _
        "GetProperties_2 hresult(ptr);" & _
        "GetNestedTypes_2 hresult(ptr);" & _
        "GetNestedType_2 hresult(bstr;ptr);" & _
        "GetMember_3 hresult(bstr;ptr);" & _
        "GetMembers_2 hresult(ptr);" & _
        "get_Attributes hresult(ptr);" & _
        "get_IsNotPublic hresult(short*);" & _
        "get_IsPublic hresult(short*);" & _
        "get_IsNestedPublic hresult(short*);" & _
        "get_IsNestedPrivate hresult(short*);" & _
        "get_IsNestedFamily hresult(short*);" & _
        "get_IsNestedAssembly hresult(short*);" & _
        "get_IsNestedFamANDAssem hresult(short*);" & _
        "get_IsNestedFamORAssem hresult(short*);" & _
        "get_IsAutoLayout hresult(short*);" & _
        "get_IsLayoutSequential hresult(short*);" & _
        "get_IsExplicitLayout hresult(short*);" & _
        "get_IsClass hresult(short*);" & _
        "get_IsInterface hresult(short*);" & _
        "get_IsValueType hresult(short*);" & _
        "get_IsAbstract hresult(short*);" & _
        "get_IsSealed hresult(short*);" & _
        "get_IsEnum hresult(short*);" & _
        "get_IsSpecialName hresult(short*);" & _
        "get_IsImport hresult(short*);" & _
        "get_IsSerializable hresult(short*);" & _
        "get_IsAnsiClass hresult(short*);" & _
        "get_IsUnicodeClass hresult(short*);" & _
        "get_IsAutoClass hresult(short*);" & _
        "get_IsArray hresult(short*);" & _
        "get_IsByRef hresult(short*);" & _
        "get_IsPointer hresult(short*);" & _
        "get_IsPrimitive hresult(short*);" & _
        "get_IsCOMObject hresult(short*);" & _
        "get_HasElementType hresult(short*);" & _
        "get_IsContextful hresult(short*);" & _
        "get_IsMarshalByRef hresult(short*);" & _
        "Equals_2 hresult(ptr;short*);"

Local Const $sIID_MethodInfo = "{FFCC1B5D-ECB8-38DD-9B01-3DC8ABC2AA5F}"
Local Const $sTag_IMethodInfo = "GetTypeInfoCount hresult();" & _
        "GetTypeInfo hresult();" & _
        "GetIDsOfNames hresult();" & _
        "Invoke hresult();" & _
        "ToString hresult();" & _
        "Equals hresult();" & _
        "GetHashCode hresult();" & _
        "GetType hresult();" & _
        "MemberType hresult();" & _
        "name hresult(bstr*);" & _
        "DeclaringType hresult();" & _
        "ReflectedType hresult();" & _
        "GetCustomAttributes hresult();" & _
        "GetCustomAttributes_2 hresult();" & _
        "IsDefined hresult();" & _
        "GetParameters hresult();" & _
        "GetMethodImplementationFlags hresult();" & _
        "MethodHandle hresult();" & _
        "Attributes hresult();" & _
        "CallingConvention hresult();" & _
        "Invoke_2 hresult();" & _
        "IsPublic hresult();" & _
        "IsPrivate hresult();" & _
        "IsFamily hresult();" & _
        "IsAssembly hresult();" & _
        "IsFamilyAndAssembly hresult();" & _
        "IsFamilyOrAssembly hresult();" & _
        "IsStatic hresult();" & _
        "IsFinal hresult();" & _
        "IsVirtual hresult();" & _
        "IsHideBySig hresult();" & _
        "IsAbstract hresult();" & _
        "IsSpecialName hresult();" & _
        "IsConstructor hresult();" & _
        "Invoke_3 hresult(variant;ptr;variant*);" & _
        "returnType hresult();" & _
        "ReturnTypeCustomAttributes hresult();" & _
        "GetBaseDefinition hresult();"

Local Const $sIID_AppDomain = "{05F696DC-2B29-3663-AD8B-C4389CF2A713}"
Local Const $sTag_AppDomain = _
        "GetTypeInfoCount hresult();" & _
        "GetTypeInfo hresult();" & _
        "GetIDsOfNames hresult();" & _
        "Invoke hresult();" & _
        "get_ToString hresult();" & _
        "Equals hresult();" & _
        "GetHashCode hresult();" & _
        "GetType hresult();" & _
        "InitializeLifetimeService hresult();" & _
        "GetLifetimeService hresult();" & _
        "get_Evidence hresult();" & _
        "add_DomainUnload hresult();" & _
        "remove_DomainUnload hresult();" & _
        "add_AssemblyLoad hresult();" & _
        "remove_AssemblyLoad hresult();" & _
        "add_ProcessExit hresult();" & _
        "remove_ProcessExit hresult();" & _
        "add_TypeResolve hresult();" & _
        "remove_TypeResolve hresult();" & _
        "add_ResourceResolve hresult();" & _
        "remove_ResourceResolve hresult();" & _
        "add_AssemblyResolve hresult();" & _
        "remove_AssemblyResolve hresult();" & _
        "add_UnhandledException hresult();" & _
        "remove_UnhandledException hresult();" & _
        "DefineDynamicAssembly hresult();" & _
        "DefineDynamicAssembly_2 hresult();" & _
        "DefineDynamicAssembly_3 hresult();" & _
        "DefineDynamicAssembly_4 hresult();" & _
        "DefineDynamicAssembly_5 hresult();" & _
        "DefineDynamicAssembly_6 hresult();" & _
        "DefineDynamicAssembly_7 hresult();" & _
        "DefineDynamicAssembly_8 hresult();" & _
        "DefineDynamicAssembly_9 hresult();" & _
        "CreateInstance hresult();" & _
        "CreateInstanceFrom hresult();" & _
        "CreateInstance_2 hresult();" & _
        "CreateInstanceFrom_2 hresult();" & _
        "CreateInstance_3 hresult();" & _
        "CreateInstanceFrom_3 hresult();" & _
        "Load hresult();" & _
        "Load_2 hresult(bstr;ptr*);" & _
        "Load_3 hresult(ptr;ptr*);" & _
        "Load_4 hresult();" & _
        "Load_5 hresult();" & _
        "Load_6 hresult();" & _
        "Load_7 hresult();" & _
        "ExecuteAssembly hresult();" & _
        "ExecuteAssembly_2 hresult();" & _
        "ExecuteAssembly_3 hresult();" & _
        "get_FriendlyName hresult();" & _
        "get_BaseDirectory hresult();" & _
        "get_RelativeSearchPath hresult();" & _
        "get_ShadowCopyFiles hresult();" & _
        "GetAssemblies hresult();" & _
        "AppendPrivatePath hresult();" & _
        "ClearPrivatePath hresult();" & _
        "SetShadowCopyPath hresult();" & _
        "ClearShadowCopyPath hresult();" & _
        "SetCachePath hresult();" & _
        "SetData hresult();" & _
        "GetData hresult();" & _
        "SetAppDomainPolicy hresult();" & _
        "SetThreadPrincipal hresult();" & _
        "SetPrincipalPolicy hresult();" & _
        "DoCallBack hresult();" & _
        "get_DynamicDirectory hresult();"

Local Const $sCLSID_CorRuntimeHost = "{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}"
Local Const $sIID_ICorRuntimeHost = "{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}"
Local $tCLSID_CorRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CorRuntimeHost)
Local $tIID_ICorRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICorRuntimeHost)
Local Const $sTag_ICorRuntimeHost = _
        "CreateLogicalThreadState hresult();" & _
        "DeleteLogicalThreadState hresult();" & _
        "SwitchInLogicalThreadState hresult();" & _
        "SwitchOutLogicalThreadState hresult();" & _
        "LocksHeldByLogicalThread hresult();" & _
        "MapFile hresult();" & _
        "GetConfiguration hresult();" & _
        "Start hresult();" & _
        "Stop hresult();" & _
        "CreateDomain hresult();" & _
        "GetDefaultDomain hresult(ptr*);" & _
        "EnumDomains hresult();" & _
        "NextDomain hresult();" & _
        "CloseEnum hresult();" & _
        "CreateDomainEx hresult();" & _
        "CreateDomainSetup hresult();" & _
        "CreateEvidence hresult();" & _
        "UnloadDomain hresult();" & _
        "CurrentDomain hresult();"


#Region CLSID & IID
Global Const $sCLSID_CLRMetaHost = "{9280188d-0e8e-4867-b30c-7fa83884e8de}"
Global Const $sIID_ICLRMetaHost = "{d332db9e-b9b3-4125-8207-a14884f53216}"
Global Const $sIID_ICLRRuntimeInfo = "{BD39D1D2-BA2F-486a-89B0-B4B0CB466891}"
Global Const $sCLSID_CLRRuntimeHost = "{90F1A06E-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $sIID_ICLRRuntimeHost = "{90F1A06C-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $sIID_IEnumUnknown = "{00000100-0000-0000-C000-000000000046}"

Global $tCLSID_CLRMetaHost = _WinAPI_CLSIDFromString($sCLSID_CLRMetaHost)
Global $tIID_ICLRMetaHost = _WinAPI_CLSIDFromString($sIID_ICLRMetaHost)
Global $tIID_ICLRRuntimeInfo = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeInfo)
Global $tCLSID_CLRRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CLRRuntimeHost)
Global $tIID_ICLRRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeHost)
Global $tIID_IEnumUnknown = _WinAPI_CLSIDFromString($sIID_IEnumUnknown)
#EndRegion CLSID & IID

Local $hMSCorEE = DllOpen("MSCorEE.DLL")
Local $aRet = DllCall($hMSCorEE, "long", "CLRCreateInstance", "struct*", $tCLSID_CLRMetaHost, "struct*", $tIID_ICLRMetaHost, "ptr*", 0)

If $aRet[0] = $S_OK Then
    Local $pClrHost = $aRet[3]
    Local $oClrHost = ObjCreateInterface($pClrHost, $sIID_ICLRMetaHost, $sTag_CLRMetaHost)
    ConsoleWrite("> oClrHost: " & IsObj($oClrHost) & @CRLF)

    #Region Get EnumerateRuntimes
    Local $tEnumerateRuntimes = DllStructCreate("ptr")
    $oClrHost.EnumerateInstalledRuntimes(DllStructGetPtr($tEnumerateRuntimes))
    Local $pEnumerateRuntimes = DllStructGetData($tEnumerateRuntimes, 1)
    ConsoleWrite("> pEnumerateRuntimes: " & $pEnumerateRuntimes & @CRLF)

    Local $oEnumerateRuntimes = ObjCreateInterface($pEnumerateRuntimes, $sIID_IEnumUnknown, $sTagEnumUnknown)
    ConsoleWrite("> oEnumerateRuntimes: " & IsObj($oEnumerateRuntimes) & @CRLF & @CRLF)


    Local $sNETFrameworkVersion = "v4.0.30319"
    Local $tCLRRuntimeInfo = DllStructCreate("ptr")

    $oClrHost.GetRuntime($sNETFrameworkVersion, $tIID_ICLRRuntimeInfo, DllStructGetPtr($tCLRRuntimeInfo))
    Local $pCLRRuntimeInfo = DllStructGetData($tCLRRuntimeInfo, 1)
    ConsoleWrite("> pCLRRuntimeInfo: " & $pCLRRuntimeInfo & @CRLF)

    Local $oCLRRuntimeInfo = ObjCreateInterface($pCLRRuntimeInfo, $sIID_ICLRRuntimeInfo, $sTag_CLRRuntimeInfo)
    ConsoleWrite("> oCLRRuntimeInfo: " & IsObj($oCLRRuntimeInfo) & @CRLF)
    Local $isIsLoadable = 0
    $oCLRRuntimeInfo.IsLoadable($isIsLoadable)
    ConsoleWrite("> IsLoadable: " & $isIsLoadable & @CRLF)

    If $isIsLoadable Then
        Local $tCLRRuntimeHost = DllStructCreate("ptr")
        $oCLRRuntimeInfo.GetInterface(DllStructGetPtr($tCLSID_CLRRuntimeHost), DllStructGetPtr($tIID_ICLRRuntimeHost), DllStructGetPtr($tCLRRuntimeHost))
        Local $pCLRRuntimeHost = DllStructGetData($tCLRRuntimeHost, 1)
        ConsoleWrite("> pCLRRuntimeHost: " & $pCLRRuntimeHost & @CRLF)
        Local $oCLRRuntimeHost = ObjCreateInterface($pCLRRuntimeHost, $sIID_ICLRRuntimeHost, $sTag_CLRRuntimeHost)
        ConsoleWrite("> oCLRRuntimeHost: " & IsObj($oCLRRuntimeHost) & @CRLF & @CRLF)


        $oCLRRuntimeHost.Start()

        Local $tCorRuntimeHost = DllStructCreate("ptr")
        $oCLRRuntimeInfo.GetInterface(DllStructGetPtr($tCLSID_CorRuntimeHost), DllStructGetPtr($tIID_ICorRuntimeHost), DllStructGetPtr($tCorRuntimeHost))
        Local $pCorRuntimeHost = DllStructGetData($tCorRuntimeHost, 1)
        ConsoleWrite("$pCorRuntimeHost = " & $pCorRuntimeHost & @CRLF)

        Local $oCorRuntimeHost = ObjCreateInterface($pCorRuntimeHost, $sIID_ICorRuntimeHost, $sTag_ICorRuntimeHost)
        ConsoleWrite("IsObj( $oCorRuntimeHost ) = " & IsObj($oCorRuntimeHost) & @CRLF)

        $oCorRuntimeHost.Start()

        Local $pAppDomain = 0
        $oCorRuntimeHost.GetDefaultDomain($pAppDomain)
        ConsoleWrite("$pAppDomain = " & Ptr($pAppDomain) & @CRLF)
        Local $oAppDomain = ObjCreateInterface($pAppDomain, $sIID_AppDomain, $sTag_AppDomain)
        ConsoleWrite("IsObj( $oAppDomain ) = " & IsObj($oAppDomain) & @CRLF & @CRLF)


        Local $bBinaryNetExe = _NETExeFile()
        Local $iSize = BinaryLen($bBinaryNetExe)
        Local $tBuffer = DllStructCreate("byte[" & $iSize & "]")
        DllStructSetData($tBuffer, 1, $bBinaryNetExe)


        Local $tSafeArrayBound = DllStructCreate($tagSAFEARRAYBOUND)
        Local $pSafeArray, $pSafeArrayData
        DllStructSetData($tSafeArrayBound, "cElements", $iSize)
        DllStructSetData($tSafeArrayBound, "lLbound", 0)
        $pSafeArray = SafeArrayCreate($VT_UI1, 1, $tSafeArrayBound)
        SafeArrayAccessData($pSafeArray, $pSafeArrayData)
        _MemMoveMemory(DllStructGetPtr($tBuffer), $pSafeArrayData, $iSize)
        SafeArrayUnaccessData($pSafeArray)

        Local $pAssembly = 0
        Local $pExeArray = $pSafeArray
        $oAppDomain.Load_3($pExeArray, $pAssembly)
        ConsoleWrite("$pAssembly: " & Ptr($pAssembly) & @CRLF)

        Local $oAssembly = ObjCreateInterface($pAssembly, $sIID_IAssembly, $sTag_IAssembly)
        ConsoleWrite("IsObj( $oAssembly ) = " & IsObj($oAssembly) & @CRLF & @CRLF)
        Local $sFullName = ""
        $oAssembly.get_FullName($sFullName)
        ConsoleWrite("$oAssembly.get_FullName: " & $sFullName & @CRLF)


        Local $pSAEmpty, $tSAB = DllStructCreate($tagSAFEARRAYBOUND)
        DllStructSetData($tSAB, "cElements", 1)
        DllStructSetData($tSAB, "lLbound", 0)
        $pSAEmpty = SafeArrayCreate($VT_VARIANT, 1, $tSAB)


        Local $pMethodInfo = 0
        $oAssembly.get_EntryPoint($pMethodInfo)
        ConsoleWrite("$pMethodInfo: " & Ptr($pMethodInfo) & @CRLF)
        Local $oMethodInfo = ObjCreateInterface($pMethodInfo, $sIID_MethodInfo, $sTag_IMethodInfo)
        ConsoleWrite("IsObj( $oMethodInfo ) = " & IsObj($oMethodInfo) & @CRLF & @CRLF)
        $oMethodInfo.Name($sFullName)
        ConsoleWrite("$oMethodInfo.Name: " & $sFullName & @CRLF)

        Local $pRet = 0
        $oMethodInfo.Invoke_3(Null, $pSAEmpty, $pRet)

        SafeArrayDestroy($pSAEmpty) ;free
        SafeArrayDestroy($pSafeArray) ;free

    EndIf

EndIf

DllClose($hMSCorEE) ;free

;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2015-01-20
Func _NETExeFile($bSaveBinary = False, $sSavePath = @ScriptDir)
    Local $NETExeFile
    $NETExeFile &= 'CrkATVqQAAMAAACCBAAw//8AALgAOC0BAEAEOBkAgAAMDh8Aug4AtAnNIbgAAUzNIVRoaXMAIHByb2dyYW0AIGNhbm5vdCAAYmUgcnVuIGkAbiBET1MgbW+AZGUuDQ0KJASGAFBFAABMAQMAEKJRGlkFV+AAIoAACwEwAAAIAAzTAQMAAHonAAQgBZgABO0BCwIDtwEABgmUABcBAIADAGCFAAAQAgJXBwcGBgIAJYArTwQpjEIFEHJgAAAMAAOc8CYAABygiQYAgE8EXRUCAAiAB0iIBy50ZfR4dAFXB4RrARaEWwghwGAucnNyY4AFgk0bgX0BdAqLEwALQC5y+GVsbwAUgVWBWYIlCXR1gxNCDVNZwVUAAMEmAlAABQBoAB00wBgDTUADAYhVJQAyckANcAQoDwApJioeAigJgCAKKsAFQlNKQg4BQRQAAMEodjQuMEAuMzAzMTlBBAWUAGxAAeSAByN+wIQFwC5swAAjU3RyaahuZ3NBCLwAeljAAWAjVVMAFMBCgTYj0EdVSUTAASTBA8EOMEJsb2LEIYAPAUcQFQAACQED+gEz7AAWAASAAhKERsEAwQNNwREOxAKDX3gBQykGAADtAPkBBgBaAgFBASEAxwEPAIIZgAgGAEkAr0AEStBCAbFCAUEBQQENFUIBJkIBYMIFNQDaFUABE0IBlEIEewCBAUABQgKjAQoAYMACLQIKAElAAcEbA0Mdw0gQAJsBVgIKQUIDUEGHAJEAqhQBKUADXUIDhhjBg0ARwzAoAgkAwcAsIhFAAQYAGUABCgCiKUABEAAxQgE5QgGqQUIBSUIBUUIBWUIBomGgABUAaWIBcaIAAnmiAIkAWwIaAIKBYgouAAsAL6AAiBMAOKAAGwBXoACCIyAcLgArAGqgACozogA7ogBD4gJLACpwoABTIgJbogBjACKIoABrALKgAHMAuL8ABOB0Ix4FAFaoeR+jX8NcawJjJQAAPE1vAGR1bGU+AG1zAGNvcmxpYgBHIHVpZEF0QEZidQB0ZQBEZWJ1ZyBnYWJsZWcCQ28gbVZpc2lqAkFzAHNlbWJseVRpAnTSAnJhZGVtYQRya0cDVGFyZ2XEdEZAnGV3bwkDZQYARmlsZVZlcnMIaW9ujwNDb25mQGlndXJhdNIDRMBlc2NyaXCLA+AWCHBpbCIGUmVsYUp4IgFzjwdQcmAiYwJ0kQ5weXJpZ2hBUgNtcGFueQcDUkB1bnRpbWXiAnRAaWJpbGl0qANUAGVzdC5leGUAgFN5c3RlbS6kBXYu5B3AdQCgEOG/JAQAEE1haW6mBWVmbARlY6EXAC5jdG8CcuUCRGlhZ25vIHN0aWNzDQtJbgB0ZXJvcFNlcjB2aWNlzgNDI2Vyf+YD4z7gEOBDwAFgNWYGVwBpbmRvd3MuRgBvcm1zAE9iagVAEQBAD2xvZ1JlEHN1bHSiGwBTaABvdwBNZXNzYSBnZUJveGBNVUhEAGUglGwAbyBQSVAAJwBt4ABhYABOEABFAFTgAEUAeAEgBCAAUgB1AG4VIABpYABn4AFGAHKrYAahBU3gA21gAXLgawIuIgABAIfRKswAQs8mQ4oKfFAA0y6H3wAEIAGAAQgDIAABBQABFBERwQEOgQACBQAAARFJDgi3elwgVhk04InAAQEdKA4IASTMHsGEVAIAFldyYXBOb24QRXhjZQJIVGhyDcAdAeAEg2YJAQAECSIcAAVCbxcBABIBJkMgwqkgIDIwADE3AAApAQAkADYzZjZlYzRlAC05ZGJiLTRlAGZiLTg3NWUtADVkNzVkYjhjEGJhOWGQXAEABwYxgFwQAAAATQEAoBwuTkVUljEsRCEiPcBeNS4yMAoOFAHGAURpc3BsYXmqTuAAFFEDIJYBINICV2Q+dYERDG0wALhweLgBYA9SU0RTablzALizk25JnsnzIIVp5ZgSQQ1jOghcdXNgB1xyYXoAaWVsXGRvY3UAbWVudHNcdmkAc3VhbCBzdHXI'
    $NETExeFile &= 'ZGlvkQ41XJAqMSAMc1xREUMAb2JqXCEwNmVhc2UCAS5wsGRiAE1EcgEAZ4WIBw8AxnQDAF9Db3JFDHhl8i9CSmVlLmSGbIFuAgD/JQAgX5Z/DwAPAA8ADwAPAA8ADwAC8/Jw0A2AGLGZ05QIANNpjjh/AaaX/wIAAGj/AlVSAIyAp5AgEPx4j/ysAjSxYLBjX1AARRA1qlMQN0+QNl9wAE4QNcHSmgC9BO/+cwRVZJ1zAD/UAFFj+2UAALGCqgFQBWFQOEYwOmwwOVpJkDpmcDkBACRSA1QV0AFhUAFz8AFhAHSNcAJv0AADALAEXIGFXTAJdFACUz6fBDgyAjARFgA0AGJQAAAAGtXyEEMSQW0QA25QBMKNVQAAIrgBcPIHedAOYVdyAraVcJIB9gZEMABza3B1cQhwegpUkgHRpQDVcAcIOANWMABysAG3AtoxkEgwNgAxBgnwArEManSyAm4wCGyYCLUFLldwADFPs6MSMANM0ABn29ICUQxw8AuRCWfQH5EIUT8BIACpMAAgEAcwc1AIYEcAKjIQdwSTGGSLklMxG2vWEgAAOnIK/k/0BJEYEQN1DtEA/wr1CqoqchRQsllkEFtj8AF7uRb5EzTyE7sCXRQ9FDhVMgNBEAJzsgtiMAl5B5AOfwN7A5xDAADqAUgr77u/PD94bShsIHZ0VCKwViIgIGVuY29kAG49IkBVVEYtOCIgTWEEbmRQbG5lPSJ5AGVzIj8+DQoNKAo8YRR+ICAEbnMAPSJ1cm46c2MCaNCMcy1taWNyAG9zb2Z0LWNvAG06YXNtLnYxgCIgbWFuaWZATyd1W/IGwAQgIMYESWSPwFQQgToJEQAiIG7wWwA9Ik15QXBwbARpYzKKLmFwcCICLxMEdHJ1c3RJuG5mb/8I/wjwCDKTB8GQA3NlY3VyMAf0ACEQAXJlcXVwCmVkEFByaXbgf2dlc3dfBV8FUAUzVQV7BHBaYwJ1EQtMZXZlbCACbFEAPSJhc0luAHZva2VyIiB1GGlBY+CFAAZmYWysc2VEDUIEL98Ic6ULMi+6CzwvRhDwADwv/UUVPp9YDwAPAA8ADwAPAAELAA+wAAAgAAAMAAAADHw3AEDwAQ=='
    $NETExeFile = _WinAPI_Base64Decode($NETExeFile)
    Local $tSource = DllStructCreate('byte[' & BinaryLen($NETExeFile) & ']')
    DllStructSetData($tSource, 1, $NETExeFile)
    Local $tDecompress
    _WinAPI_LZNTDecompress($tSource, $tDecompress, 4608)
    $tSource = 0
    Local Const $bString = Binary(DllStructGetData($tDecompress, 1))
    If $bSaveBinary Then
        Local Const $hFile = FileOpen($sSavePath & "\Test.exe", 18)
        If @error Then Return SetError(1, 0, 0)
        FileWrite($hFile, $bString)
        FileClose($hFile)
    EndIf
    Return $bString
EndFunc   ;==>_NETExeFile

Func _WinAPI_Base64Decode($sB64String)
    Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
    Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
    $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($bBuffer, 1)
EndFunc   ;==>_WinAPI_Base64Decode

Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iBufferSize)
    $tOutput = DllStructCreate("byte[" & $iBufferSize & "]")
    If @error Then Return SetError(1, 0, 0)
    Local $aRet = DllCall("ntdll.dll", "uint", "RtlDecompressBuffer", "ushort", 0x0002, "struct*", $tOutput, "ulong", $iBufferSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0)
    If @error Then Return SetError(2, 0, 0)
    If $aRet[0] Then Return SetError(3, $aRet[0], 0)
    Return $aRet[6]
EndFunc   ;==>_WinAPI_LZNTDecompress


Func _WinAPI_CLSIDFromString($sGUID)
    Local $tGUID = DllStructCreate('ulong Data1;ushort Data2;ushort Data3;byte Data4[8]')
    Local $iRet = DllCall('ole32.dll', 'uint', 'CLSIDFromString', 'wstr', $sGUID, 'ptr', DllStructGetPtr($tGUID))
    If (@error) Or ($iRet[0]) Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return $tGUID
EndFunc   ;==>_WinAPI_CLSIDFromString

Saludos

Share this post


Link to post
Share on other sites

Great Example again to add to the Examples Library ... I will update in the next days....

I was playing with the GetTypes based on Junkew 's attempt...

This is how far I got, now stuck at the SafeArray handle... not sure how to move on.

Example1()

Func Example1()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

    Local $pTypes
    $oAssembly.GetTypes($pTypes)

    Local $iDim = SafeArrayGetDim( $pTypes )
    ConsoleWrite( "$iDim = " & $iDim & @CRLF & @CRLF )

    Local $iLBound, $iUBound
    SafeArrayGetLBound( $pTypes, 1, $iLBound )
    SafeArrayGetUBound( $pTypes, 1, $iUBound )
    ConsoleWrite( "$iLBound = " & $iLBound & @CRLF )
    ConsoleWrite( "$iUBound = " & $iUBound & @CRLF )
    ConsoleWrite(@CRLF)

    Local $tAssemblyArray = DllStructCreate( $tagSAFEARRAY, $pTypes )
    Local $fFeatures = DllStructGetData( $tAssemblyArray, "fFeatures" )
    ConsoleWrite("fFeatures " & $fFeatures & @CRLF & @CRLF)

    Local $pvData = DllStructGetData( $tAssemblyArray, "pvData" )
    ConsoleWrite("pvData " & $pvData & @CRLF & @CRLF)

 EndFunc

 Returned data :

Quote

$oAssembly: 1
$iDim = 1

$iLBound = 0
$iUBound = 3232

fFeatures 576

pvData 0x00C03E98

 

 


Share this post


Link to post
Share on other sites

No success ?

 

;~  #AutoIt3Wrapper_UseX64=y
#include "CLR.Au3"

Example1()

Func Example1()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

    Local $pTypes
    $oAssembly.GetTypes($pTypes)

    Local $iDim = SafeArrayGetDim( $pTypes )
    ConsoleWrite( "$iDim = " & $iDim & @CRLF & @CRLF )

    Local $iLBound, $iUBound
    SafeArrayGetLBound( $pTypes, 1, $iLBound )
    SafeArrayGetUBound( $pTypes, 1, $iUBound )
    ConsoleWrite( "$iLBound = " & $iLBound & @CRLF )
    ConsoleWrite( "$iUBound = " & $iUBound & @CRLF )
    ConsoleWrite(@CRLF)

    ; Array Var.
    Local $tAssemblyArray = DllStructCreate( $tagSAFEARRAY, $pTypes )

    ; Get # Features
    Local $fFeatures = DllStructGetData( $tAssemblyArray, "fFeatures" )
    ConsoleWrite("fFeatures " & $fFeatures & @CRLF & @CRLF)

    ; Get Point to the Array Data
    Local $pvData = DllStructGetData( $tAssemblyArray, "pvData" )
    ConsoleWrite("pvData " & $pvData & @CRLF & @CRLF)

    ; Get Array element 1 ;
    Local $Ret, $vt, $Index = 1

    $Ret = SafeArrayGetElement($pvData, $Index, $vt)
    ConsoleWrite($Ret & @CRLF)

 EndFunc

Func SafeArrayGetElement($pSA, $rgIndices, $pv)
;~     Local $aCall = DllCall( "oleaut32.dll", "long", "SafeArrayGetElement", "ptr", $pSA, "long*", $rgIndices, 'ptr', 0)
    Local $aCall = DllCall("OleAut32.dll", "long", "SafeArrayGetElement", "ptr", $pSA, "LONG", $rgIndices, 'ptr', $pv)
    If @error Then Return SetError(1, 0, 0)
    Return $aCall[0]
EndFunc

 

Result 

Quote

-2147024809

 


Share this post


Link to post
Share on other sites

Here you have ptrex,

 

;~  #AutoIt3Wrapper_UseX64=y
;~ #include <WinAPI.au3>
#include ".\includes\CLR.Au3"


Example1()

Func Example1()
    Local $oType = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oType: " & IsObj($oType) & @CRLF)

    Local $pTypes
    $oType.GetTypes($pTypes)

    Local $iDim = SafeArrayGetDim($pTypes)
    ConsoleWrite("$iDim = " & $iDim & @CRLF)

    Local $iLBound, $iUBound
    SafeArrayGetLBound($pTypes, 1, $iLBound)
    SafeArrayGetUBound($pTypes, 1, $iUBound)
    ConsoleWrite("$iLBound = " & $iLBound & @CRLF)
    ConsoleWrite("$iUBound = " & $iUBound & @CRLF)
    Local $tTypeArray = DllStructCreate($tagSAFEARRAY, $pTypes)
    Local $iPtrSize=(DllStructGetData($tTypeArray, "cbElements"))
    ConsoleWrite(".cDims = " & (DllStructGetData($tTypeArray, "cDims")) & @CRLF)
    ConsoleWrite(".fFeatures = 0x" & Hex(DllStructGetData($tTypeArray, "fFeatures")) & @CRLF)
    ConsoleWrite(".cbElements = " & $iPtrSize & @CRLF)

    Local $vt=0
    SafeArrayGetVartype($pTypes, $vt)
    ConsoleWrite("$vt = " & $vt & @CRLF)

;   Add #include <WinAPI.au3>
;~  Local $tGUID = $tagGUID
;~  Local $tGUID = DllStructCreate($tagGUID, $pTypes - 16)
;~  Local $sGUID = _WinAPI_StringFromGUID($tGUID)
;~  ConsoleWrite("$sGUID = " & $sGUID & @CRLF)

    Local $pTypeArrayData = 0
    Local $tType=0
    Local $pType=0
    Local $oType=Null
    Local $sFullName=""
    For $i = 0 To $iUBound
        SafeArrayAccessData($pTypes, $pTypeArrayData)
        $tType = DllStructCreate("ptr", $pTypeArrayData + ($i * $iPtrSize))
        $pType = DllStructGetData($tType, 1)
        ConsoleWrite("$pType = " & $pType & @CRLF)
        SafeArrayUnaccessData($pTypes)

        $oType = ObjCreateInterface($pType, $sIID_IType, $sTag_IType)
        ConsoleWrite("IsObj( $oType ) = " & IsObj($oType) & @CRLF)

        $oType.get_FullName($sFullName)
        ConsoleWrite("$sFullName = " & $sFullName & @CRLF & @CRLF)
        $sFullName=""
        $pType= 0
        $tType=0
        $oType = Null
    Next

EndFunc   ;==>Example1

Saludos

Share this post


Link to post
Share on other sites

Spot on again ! What should we do without you  :graduated:

2 Examples to add to the Example Libr.

The GetTypes is an important one to make again a next step up...

I will update the other thread later today or tomorrow... then I will be out for a while (have a quick vacation in between). I can read but not actively participate in the meantime.

So if you want me to do more updates let me know ASAP ...

See you all soon...


Share this post


Link to post
Share on other sites

SafeArrayGetElement was not returning $aCall[3] so thats the reason its not working with safearraygetelement

;~ HRESULT SafeArrayGetElement(  _In_  SAFEARRAY *psa,  _In_  LONG      *rgIndices,  _Out_ void      *pv);
Func SafeArrayGetElement($pSA, $rgIndices, $pv)
    Local $aCall = DllCall("OleAut32.dll", "long", "SafeArrayGetElement", "ptr", $pSA, "long*", $rgIndices, 'uint_ptr*', $pv)
    If @error Then Return SetError(1, 0, 0)
    Return $aCall[3]
EndFunc

or should it be coding style like (but then byref $pv and then not pass ptr($pv)????)

$pv=$aCall[3]

 

see post 240

Edited by junkew
see post 240

Share this post


Link to post
Share on other sites

Hi junkew, this is a nice fix you posted !!  :graduated:

Good to see  we can have the SafeArrayGetElement going. We are getting there slowly be steadily ....

I can't comment whether you approach is making sense are not. I will leave this up to the SafeArray specialists... 

Any how I would say that as we have the CLR GetTypes running, we should go for the CLR GetMembers as the next challenge... 

 

"GetMembers hresult(int;ptr);" & _

Once we get this going, I guess we start having a Swiss army knife for .NET CLR... 

If I get something going I will post what I have... anyhow it won't be in the next 2 weeks...

 


Share this post


Link to post
Share on other sites

here is the Example of GetMembers.

need to change GetMembers in $sTagIType declaration from GetMembers(Int;ptr) to GetMembers(Int;ptr*)

 

;~  #AutoIt3Wrapper_UseX64=y
;~ #include <WinAPI.au3>
#include ".\includes\CLR.Au3"


Global Const $sIID_IMemberInfo = '{F7102FA9-CABB-3A74-A6DA-B4567EF1B079}'
Global Const $sTag_IMemberInfo = "GetTypeInfoCount hresult();" & _
        "GetTypeInfo hresult();" & _
        "GetIDsOfNames hresult();" & _
        "Invoke hresult();" & _
        "get_ToString hresult(bstr*);" & _
        "Equals hresult();" & _
        "GetHashCode hresult();" & _
        "GetType hresult();" & _
        "MemberType hresult();" & _
        "get_FullName hresult(bstr*);" & _
        "DeclaringType hresult();" & _
        "ReflectedType hresult();" & _
        "GetCustomAttributes hresult();" & _
        "GetCustomAttributes_2 hresult();" & _
        "IsDefined hresult();"

Example1()




Func Example1()
    Local $oType = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oType: " & IsObj($oType) & @CRLF)

    Local $pTypes
    $oType.GetTypes($pTypes)

    Local $iDim = SafeArrayGetDim($pTypes)
    ConsoleWrite("$iDim = " & $iDim & @CRLF)

    Local $iLBound, $iUBound
    SafeArrayGetLBound($pTypes, 1, $iLBound)
    SafeArrayGetUBound($pTypes, 1, $iUBound)
    ConsoleWrite("$iLBound = " & $iLBound & @CRLF)
    ConsoleWrite("$iUBound = " & $iUBound & @CRLF)
    Local $tTypeArray = DllStructCreate($tagSAFEARRAY, $pTypes)
    Local $iPtrSize = (DllStructGetData($tTypeArray, "cbElements"))
    ConsoleWrite(".cDims = " & (DllStructGetData($tTypeArray, "cDims")) & @CRLF)
    ConsoleWrite(".fFeatures = 0x" & Hex(DllStructGetData($tTypeArray, "fFeatures")) & @CRLF)
    ConsoleWrite(".cbElements = " & $iPtrSize & @CRLF)

    Local $vt = 0
    SafeArrayGetVartype($pTypes, $vt)
    ConsoleWrite("$vt = " & $vt & @CRLF)

    ;   Add #include <WinAPI.au3>
;~  Local $tGUID = $tagGUID
;~  Local $tGUID = DllStructCreate($tagGUID, $pTypes - 16)
;~  Local $sGUID = _WinAPI_StringFromGUID($tGUID)
;~  ConsoleWrite("$sGUID = " & $sGUID & @CRLF)

    ;Type
    Local $pTypeArrayData = 0
    Local $tType = 0
    Local $pType = 0
    Local $oType = Null
    Local $sFullName = ""
    Local $pSafeArrayMembers = 0

    ;memberInfo
    Local $pTypeArrayDataMembers = 0
    Local $tMemberInfo = 0
    Local $pMemberInfo = 0
    Local $oMemberInfo = Null
    Local $sFullNameMemberInfo = ""

    ConsoleWrite(@CRLF & @CRLF)
    For $i = 0 To $iUBound
        SafeArrayAccessData($pTypes, $pTypeArrayData)
        $tType = DllStructCreate("ptr", $pTypeArrayData + ($i * $iPtrSize))
        $pType = DllStructGetData($tType, 1)
;~      ConsoleWrite("$pType = " & $pType & @CRLF)
        SafeArrayUnaccessData($pTypes)

        $oType = ObjCreateInterface($pType, $sIID_IType, $sTag_IType)
;~      ConsoleWrite("IsObj( $oType ) = " & IsObj($oType) & @CRLF)

        $oType.get_FullName($sFullName)
        ConsoleWrite("+TypeName = " & $sFullName & @CRLF)

        $oType.GetMembers(4 + 8 + 16, $pSafeArrayMembers)
;~      ConsoleWrite("$pSafeArrayMember = " & $pSafeArrayMembers & @CRLF & @CRLF)

        Local $iDimSafeArrayMembers = SafeArrayGetDim($pSafeArrayMembers)
;~      ConsoleWrite("$iDimSafeArrayMembers = " & $iDimSafeArrayMembers & @CRLF)

        Local $iLBoundMembers, $iUBoundMembers
        SafeArrayGetLBound($pSafeArrayMembers, 1, $iLBoundMembers)
        SafeArrayGetUBound($pSafeArrayMembers, 1, $iUBoundMembers)
;~      ConsoleWrite("$iLBoundMembers = " & $iLBoundMembers & @CRLF)
;~      ConsoleWrite("$iUBoundMembers = " & $iUBoundMembers & @CRLF)
        Local $tMembersArray = DllStructCreate($tagSAFEARRAY, $pSafeArrayMembers)
        Local $iPtrMembersSize = (DllStructGetData($tMembersArray, "cbElements"))
;~      ConsoleWrite(".cDims = " & (DllStructGetData($tMembersArray, "cDims")) & @CRLF)
;~      ConsoleWrite(".fFeatures = 0x" & Hex(DllStructGetData($tMembersArray, "fFeatures")) & @CRLF)
;~      ConsoleWrite(".cbElements = " & $iPtrMembersSize  & @CRLF)


;~      SafeArrayGetVartype($pSafeArrayMembers, $vt)
;~      ConsoleWrite("$vt2 = " & $vt & @CRLF)


;~      Local $tGUID2 = $tagGUID
;~      Local $tGUID2 = DllStructCreate($tagGUID, $pSafeArrayMembers - 16)
;~      Local $sGUID2 = _WinAPI_StringFromGUID($tGUID2)
;~      ConsoleWrite("$sGUID2 = " & $sGUID2 & @CRLF)



        ConsoleWrite("> (" & $sFullName & ") Number of Members: " & $iUBoundMembers & @CRLF)
        For $x = 0 To $iUBoundMembers
            SafeArrayAccessData($pSafeArrayMembers, $pTypeArrayDataMembers)
            $tMemberInfo = DllStructCreate("ptr", $pTypeArrayDataMembers + ($x * $iPtrMembersSize))
            $pMemberInfo = DllStructGetData($tMemberInfo, 1)
;~          ConsoleWrite("$pMemberinfo = " & $pMemberinfo & @CRLF)
            SafeArrayUnaccessData($pSafeArrayMembers)

            $oMemberInfo = ObjCreateInterface($pMemberInfo, $sIID_IMemberInfo, $sTag_IMemberInfo) ;
;~          ConsoleWrite("IsObj( $oType ) = " & IsObj($oMemberinfo) & @CRLF)

            $oMemberInfo.get_FullName($sFullNameMemberInfo)
            ConsoleWrite($sFullNameMemberInfo & @CRLF)


            $sFullNameMemberInfo = ""
            $pMemberInfo = 0
            $tMemberInfo = 0
            $oMemberInfo = Null

        Next

        ConsoleWrite(@CRLF & @CRLF)



        $sFullName = ""
        $pType = 0
        $tType = 0
        $oType = Null
        $pSafeArrayMembers = 0
;~      Exit
    Next

EndFunc   ;==>Example1

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Thank you LarsJ I really have no read about that functions before.

 

Saludos

Share this post


Link to post
Share on other sites

not sure whom is maintainer of safearray.au3 but these 3 functions should be in there @LarsJ did you write safearray.au3 based on the AIO library? maybe merge safearray.au3 and variant.au3 to oleaut32.au3 as both libraries wrap the oleAut32.dll.

Looks like it originated here

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1149440

 

Improved the SafeArrayGetElement for single dimension array you just past the integer instead of an array (handled now in the function)

SafeArrayGetElement($pTypes, $index, $pType)

is more natural then it was before

Example attached replacing the previous post (will remove that part of that post)

;~ SAFEARRAY* SafeArrayCreateVector(_In_ VARTYPE vt,  _In_ LONG    lLbound,  _In_ ULONG   cElements);
Func SafeArrayCreateVector($vType, $ilBound, $cElements)
    Local $aRet  = DllCall("OleAut32.dll", "ptr", "SafeArrayCreateVector", "dword", $vType, "LONG", $ilBound, 'ULONG', $cElements)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc
;~ HRESULT SafeArrayPutElement(  _In_ SAFEARRAY *psa,  _In_ LONG      *rgIndices,  _In_ void      *pv);
Func SafeArrayPutElement($pSA, $rgIndices, $pv)
    Local $aRet = DllCall("OleAut32.dll", "long", "SafeArrayPutElement", "ptr", $pSA, "LONG", $rgIndices, 'ptr', $pv)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc
;~ HRESULT SafeArrayGetElement(  _In_  SAFEARRAY *psa,  _In_  LONG      *rgIndices,  _Out_ void      *pv);
Func SafeArrayGetElement($pSA, $rgIndices, ByRef $pv)
;~  If its a single dimension then we get an integer and not an array
    if not isarray($rgIndices) then
        local $tArr[1]
        $tArr[0]=$rgIndices
        Local $aRet = DllCall("OleAut32.dll", "long", "SafeArrayGetElement", "ptr", $pSA, "long*", $tArr[0], 'uint_ptr*', $pv)
    Else
        Local $aRet = DllCall("OleAut32.dll", "long", "SafeArrayGetElement", "ptr", $pSA, "long*", $rgIndices, 'uint_ptr*', $pv)
    EndIf

    If @error Then Return SetError(1, 0, 0)
    $pv = $aRet[3]
    Return $aRet[0]
EndFunc
#AutoIt3Wrapper_UseX64=n

#include "CLR.Au3"

Example()

Func Example()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF)

    Local $pTypes
    $oAssembly.GetTypes($pTypes)

    Local $iDim = SafeArrayGetDim( $pTypes )
    ConsoleWrite( "$iDim = " & $iDim & @CRLF & @CRLF )

    Local $iLBound, $iUBound
    SafeArrayGetLBound( $pTypes, 1, $iLBound )
    SafeArrayGetUBound( $pTypes, 1, $iUBound )
    ConsoleWrite( "$iLBound = " & $iLBound & @CRLF )
    ConsoleWrite( "$iUBound = " & $iUBound & @CRLF )
    ConsoleWrite(@CRLF)

    ; Array Var.
    Local $tAssemblyArray = DllStructCreate( $tagSAFEARRAY, $pTypes )

    ; Get # Features
    Local $fFeatures = DllStructGetData( $tAssemblyArray, "fFeatures" )
    ConsoleWrite("fFeatures " & $fFeatures & @CRLF & @CRLF)

    ; Get Point to the Array Data
    Local $pvData = DllStructGetData( $tAssemblyArray, "pvData" )
    ConsoleWrite("pvData " & $pvData & @CRLF & @CRLF)

    Local $Ret,  $Index =1
    Local $vt=0

    SafeArrayGetVartype($pTypes, $vt)
    ConsoleWrite("$vt = " & $vt & @CRLF)
    $vt=0

    for $index=1 to $iUBound
;~  for $index=1 to 15

;~      local $rgIndices[1]
;~      $rgindices[0]=$Index

        Local $pType=0
        Local $sFullName=""

;~      $pType = SafeArrayGetElement($pTypes, $rgindices[0], ptr($pType))
        SafeArrayGetElement($pTypes, $index, $pType)
        local $vt2=0
        SafeArrayGetVartype($pType, $vt2)

        ConsoleWrite("$vt2 = " & $vt2 & @CRLF)

        $oType = ObjCreateInterface($pType, $sIID_IType, $sTag_IType)
        $oType.get_FullName($sFullName)
        ConsoleWrite("IsObj( $oType ) = " & IsObj($oType) )
        ConsoleWrite(" $sFullName = " & $sFullName & @CRLF )

    Next
 EndFunc
Edited by junkew

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gowrisankar
      Dear members of the forum,
      I'm working on a project in which I have to use Image recognition technique. 
      Due to client restrictions, I couldn't use AutoIt for this project. 
      Is there a way to use this DLL "ImageSearchDLL.dll" (which is used to do image recognition steps in AutoIt) in VB.Net to achieve the same result? 
      I have used this DLL few years before and got good results. If there is a latest version of this DLL and if you can share it, that will be helpful too.
      Any guidance is deeply appreciated.
    • By Colduction
      Hi AutoIt Scripters/Programmers. I have a question about MIME Tools for Notepad++:
      I've recently found a UDF about Base64 in forum, but they can't decode\encode correctly some emojis , other UTFs and etc. so i decided to use mimeTools.dll of Notepad++ or main site
      My problem is how to use this dll in AutoIt Language?

      I will be happy with your comments and answers❤ Thanks.
    • By FrancescoDiMuro
      Good morning Forums 
      In these days, I am working on a project that involved me to use some Windows APIs to obtain some information about Terminal Servers.
      I'm doing this using wtsapi32.dll in a VBA Project, but, the lack of knowledge about few things threated in the articles make this quite difficult to
      implement and understand at the same time.
      The most difficult thing I'm facing is "translating" C/C++ functions or struct in VBA when pointers are used, or pointers of pointers, and so on.
      Since VBA seems to not have a pointer type, to make those functions work I need to implement other functions taken from other DLLs, and this confuses me a lot.
      For example, starting from this code, I splitted all the functions and all the definitions to understand why they are there, and why I need to use them.
      At the end, I've found out that the code I was going to implement starting from the functions provided in the Microsoft Docs won't be ever be able to work without some supplementary functions which are not mentioned anywhere.
      So, I was wondering if someone would please point me out to a good and practical exaplanation about pointers (in general) or specifically for VBA, because I need to use them quite often in these days, and I'd like to understand what I am doing.
      Thanks in advance.

      Best Regards and Stay at home 🏡
       
    • By zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
    • By RAMzor
      Hello all!
      I got the Acroname Programmable USB Hub based on BrainStem platform. I will use it to manage ports and read current.
      They have development kit (BRAINSTEM DEVELOPMENT KIT) with examples for any languages like C#, C++, LabVIEW and python but no AutoIt.
      The kit include BrainStem2.dll (x32 and x64), BrainStem2_LabVIEW.dll, BrainStem2CLI.dll and many examples.
      Anyone used this dll and implemented it in AutoIt?
      Please share some example for Device Discovering, User LED Flashing or power enable/disable on port to start play with this HUB
      BrainStem Reference 
       
      BrainStem2 lib+example.7z USB HUB User Manual s79-usbhub-3p_v1.10_0.pdf
×
×
  • Create New...