Jump to content

Using .NET libary with AutoIt, possible?


Recommended Posts

The first AutoHotkey example (tst00.ahk about XPTable.dll assembly) is translated:

;#AutoIt3Wrapper_UseX64=y

#include "SafeArray.au3"
#include "Variant.au3"

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

Func _WinAPI_SetParent($hWndChild, $hWndParent)
  Local $aResult = DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $hWndParent)
  If @error Then Return SetError(@error, @extended, 0)

  Return $aResult[0]
EndFunc   ;==>_WinAPI_SetParent

Global Const $S_OK = 0

Global Const $sCLSID_CLRMetaHost = "{9280188d-0e8e-4867-b30c-7fa83884e8de}"
Global Const $tCLSID_CLRMetaHost = _WinAPI_CLSIDFromString($sCLSID_CLRMetaHost)
Global Const $sIID_ICLRMetaHost = "{d332db9e-b9b3-4125-8207-a14884f53216}"
Global Const $tIID_ICLRMetaHost = _WinAPI_CLSIDFromString($sIID_ICLRMetaHost)
Global Const $sTag_ICLRMetaHost = _
  "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 $sIID_ICLRRuntimeInfo = "{BD39D1D2-BA2F-486a-89B0-B4B0CB466891}"
Global Const $tIID_ICLRRuntimeInfo = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeInfo)
Global Const $sTag_ICLRRuntimeInfo = _
  "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 $sCLSID_CLRRuntimeHost = "{90F1A06E-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $tCLSID_CLRRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CLRRuntimeHost)
Global Const $sIID_ICLRRuntimeHost = "{90F1A06C-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $tIID_ICLRRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeHost)
Global Const $sTag_ICLRRuntimeHost = _
  "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 $sCLSID_CorRuntimeHost = "{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}"
Global Const $tCLSID_CorRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CorRuntimeHost)
Global Const $sIID_ICorRuntimeHost = "{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}"
Global Const $tIID_ICorRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICorRuntimeHost)
Global 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();"

Global Const $sIID_IAppDomain = "{05F696DC-2B29-3663-AD8B-C4389CF2A713}"
Global Const $sTag_IAppDomain = _
  "GetTypeInfoCount hresult();" & _
  "GetTypeInfo hresult();" & _
  "GetIDsOfNames hresult();" & _
  "Invoke hresult();" & _
  "get_ToString hresult();" & _
  "Equals hresult();" & _
  "GetHashCode hresult();" & _
  "GetType hresult(ptr*);" & _
  "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(bstr;bstr;object*);" & _
  "CreateInstanceFrom hresult();" & _
  "CreateInstance_2 hresult();" & _
  "CreateInstanceFrom_2 hresult();" & _
  "CreateInstance_3 hresult();" & _
  "CreateInstanceFrom_3 hresult();" & _
  "Load hresult();" & _
  "Load_2 hresult();" & _
  "Load_3 hresult();" & _
  "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 ) = 0; hresult();" & _
  "SetShadowCopyPath hresult();" & _
  "ClearShadowCopyPath ) = 0; hresult();" & _
  "SetCachePath hresult();" & _
  "SetData hresult();" & _
  "GetData hresult();" & _
  "SetAppDomainPolicy hresult();" & _
  "SetThreadPrincipal hresult();" & _
  "SetPrincipalPolicy hresult();" & _
  "DoCallBack hresult();" & _
  "get_DynamicDirectory hresult();"

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

; InvokeMember, InvokeMember_2, InvokeMember_3
Global Const $BindingFlags_Default = 0x0000
Global Const $BindingFlags_IgnoreCase = 0x0001
Global Const $BindingFlags_DeclaredOnly = 0x0002
Global Const $BindingFlags_Instance = 0x0004
Global Const $BindingFlags_Static = 0x0008
Global Const $BindingFlags_Public = 0x0010
Global Const $BindingFlags_NonPublic = 0x0020
Global Const $BindingFlags_FlattenHierarchy = 0x0040
Global Const $BindingFlags_InvokeMethod = 0x0100
Global Const $BindingFlags_CreateInstance = 0x0200
Global Const $BindingFlags_GetField = 0x0400
Global Const $BindingFlags_SetField = 0x0800
Global Const $BindingFlags_GetProperty = 0x1000
Global Const $BindingFlags_SetProperty = 0x2000
Global Const $BindingFlags_PutDispProperty = 0x4000
Global Const $BindingFlags_PutRefDispProperty = 0x8000
Global Const $BindingFlags_ExactBinding = 0x00010000
Global Const $BindingFlags_SuppressChangeType = 0x00020000
Global Const $BindingFlags_OptionalParamBinding = 0x00040000
Global Const $BindingFlags_IgnoreReturn = 0x01000000

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();" & _
  "Equals hresult();" & _
  "GetHashCode hresult();" & _
  "GetType hresult(ptr*);" & _
  "get_CodeBase hresult();" & _
  "get_EscapedCodeBase hresult();" & _
  "GetName hresult();" & _
  "GetName_2 hresult();" & _
  "get_FullName hresult();" & _
  "get_EntryPoint hresult();" & _
  "GetType_2 hresult();" & _
  "GetType_3 hresult();" & _
  "GetExportedTypes hresult();" & _
  "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();" & _
  "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();"


Example()

Func Example()
  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_ICLRMetaHost)
    ConsoleWrite(">oClrHost: " & IsObj($oClrHost) & @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_ICLRRuntimeInfo)
    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_ICLRRuntimeHost)
      ConsoleWrite(">oCLRRuntimeHost: " & IsObj($oCLRRuntimeHost) & @CRLF)

      $oCLRRuntimeHost.Start()

      ;Local $iRet = 0
      ;$oCLRRuntimeHost.ExecuteInDefaultAppDomain(@ScriptDir & "\C#Library.dll", "ClassLibraryDemo.ClassDemo", "NetMsgBox", "AutoIt Rocks!!! " & @CRLF & "Danyfirex does too lol!!!", $iRet)
      ;ConsoleWrite(">Ret: " & $iRet & @CRLF)

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

      ; tst00.ahk
      ; CLR_LoadLibrary
      ; assembly := typeofAssembly.InvokeMember_3("LoadFrom", 0x158, null, null, args)

      Local $pAppDomain = 0
      $oCorRuntimeHost.GetDefaultDomain($pAppDomain)
      ConsoleWrite("$pAppDomain = " & Ptr($pAppDomain) & @CRLF)

      Local $oAppDomain = ObjCreateInterface($pAppDomain, $sIID_IAppDomain, $sTag_IAppDomain)
      ConsoleWrite("IsObj( $oAppDomain ) = " & IsObj($oAppDomain) & @CRLF)

      Local $pType
      $oAppDomain.GetType( $pType )
      ConsoleWrite( "$pType = " & Ptr( $pType ) & @CRLF )

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

      Local $pAssembly
      $oType.get_Assembly( $pAssembly )
      ConsoleWrite( "$pAssembly = " & Ptr( $pAssembly ) & @CRLF )

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

      Local $pAssemblyType
      $oAssembly.GetType( $pAssemblyType )
      ConsoleWrite( "$pAssemblyType = " & Ptr( $pAssemblyType ) & @CRLF )

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

      ; args := ComObjArray(0xC, 1),  args[0] := "XPTable.dll"
      Local $tSafeArrayBound = DllStructCreate( $tagSAFEARRAYBOUND )
      Local $pSafeArray, $pSafeArrayData
      DllStructSetData( $tSafeArrayBound, "cElements", 1 )
      DllStructSetData( $tSafeArrayBound, "lLbound", 0 )
      $pSafeArray =  SafeArrayCreate( $VT_VARIANT, 1, $tSafeArrayBound )
      SafeArrayAccessData( $pSafeArray, $pSafeArrayData )
      DllStructSetData( DllStructCreate( "word", $pSafeArrayData ), 1, $VT_BSTR )
      DllStructSetData( DllStructCreate( "ptr", $pSafeArrayData + 8 ), 1, SysAllocString( "XPTable.dll" ) )
      SafeArrayUnaccessData( $pSafeArray )

      Local $pXPTable
      $oAssemblyType.InvokeMember_3( "LoadFrom", 0x158, 0, 0, $pSafeArray, $pXPTable )
      ConsoleWrite( "$pXPTable = " & Ptr( $pXPTable ) & @CRLF )

      Local $oXPTable = ObjCreateInterface( $pXPTable, $sIID_IAssembly, $sTag_IAssembly )
      ConsoleWrite( "IsObj( $oXPTable ) = " & IsObj( $oXPTable ) & @CRLF )

      ; table       := CLR_CreateObject(xptables,"XPTable.Models.Table")
      ; columnModel := CLR_CreateObject(xptables,"XPTable.Models.ColumnModel")
      ; tableModel  := CLR_CreateObject(xptables,"XPTable.Models.TableModel")
      Local $oTable, $oColumnModel, $oTableModel
      $oXPTable.CreateInstance_2( "XPTable.Models.Table", True, $oTable )
      $oXPTable.CreateInstance_2( "XPTable.Models.ColumnModel", True, $oColumnModel )
      $oXPTable.CreateInstance_2( "XPTable.Models.TableModel", True, $oTableModel )
      ConsoleWrite( "IsObj( $oTable ) = " & IsObj( $oTable ) & @CRLF )
      ConsoleWrite( "IsObj( $oColumnModel ) = " & IsObj( $oColumnModel ) & @CRLF )
      ConsoleWrite( "IsObj( $oTableModel ) = " & IsObj( $oTableModel ) & @CRLF )
      
      $oTable.ColumnModel() = $oColumnModel
      $oTable.TableModel() = $oTableModel

      ; static Array_Empty := ComObjArray(0xC,0), null := ComObject(13,0)
      Local $pSAEmpty, $tSAB = DllStructCreate( $tagSAFEARRAYBOUND )
      DllStructSetData( $tSAB, "cElements", 0 )
      DllStructSetData( $tSAB, "lLbound", 0 )
      $pSAEmpty =  SafeArrayCreate( $VT_VARIANT, 0, $tSAB )

      ; columnModel.Columns.Add(CLR_CreateObject(xptables, "XPTable.Models.TextColumn", "MyTextColumn"))
      ; columnModel.Columns.Add(CLR_CreateObject(xptables, "XPTable.Models.CheckBoxColumn", "MyCheckBoxColumn"))
      ; columnModel.Columns.Add(CLR_CreateObject(xptables, "XPTable.Models.ButtonColumn", "MyButtonColumn"))
      Local $oColumn0, $oColumn1, $oColumn2
      $oXPTable.CreateInstance_3( "XPTable.Models.TextColumn", True, 0, 0, CreateSafeArray( "MyTextColumn" ), 0, $pSAEmpty, $oColumn0 )
      $oXPTable.CreateInstance_3( "XPTable.Models.CheckBoxColumn", True, 0, 0, CreateSafeArray( "CheckBoxColumn" ), 0, $pSAEmpty, $oColumn1 )
      $oXPTable.CreateInstance_3( "XPTable.Models.ButtonColumn", True, 0, 0, CreateSafeArray( "MyButtonColumn" ), 0, $pSAEmpty, $oColumn2 )
      ConsoleWrite( "IsObj( $oColumn0 ) = " & IsObj( $oColumn0 ) & @CRLF )
      ConsoleWrite( "IsObj( $oColumn1 ) = " & IsObj( $oColumn1 ) & @CRLF )
      ConsoleWrite( "IsObj( $oColumn2 ) = " & IsObj( $oColumn2 ) & @CRLF )

      $oColumnModel.Columns.Add( $oColumn0 )
      $oColumnModel.Columns.Add( $oColumn1 )
      $oColumnModel.Columns.Add( $oColumn2 )
      ConsoleWrite( "VisibleColumnCount = " & $oColumnModel.VisibleColumnCount() & @CRLF )

      Local $oRow
      $oXPTable.CreateInstance_2( "XPTable.Models.Row", True, $oRow )
      ConsoleWrite( "IsObj( $oRow ) = " & IsObj( $oRow ) & @CRLF )
      $oTableModel.Rows.Add( $oRow )
      ConsoleWrite( "Rows = " & $oTableModel.Rows.Count() & @CRLF )

      ; tableModel.Rows.Item(0).Cells.Add(CLR_CreateObject(xptables, "XPTable.Models.Cell", "MyCell1"))
      ; tableModel.Rows.Item(0).Cells.Add(CLR_CreateObject(xptables, "XPTable.Models.Cell", "MyCheckbox1", true))
      ; tableModel.Rows.Item(0).Cells.Add(CLR_CreateObject(xptables, "XPTable.Models.Cell", "MyButton1"))
      Local $oCell0, $oCell1, $oCell2
      $oXPTable.CreateInstance_3( "XPTable.Models.Cell", True, 0, 0, CreateSafeArray( "MyCell1" ), 0, $pSAEmpty, $oCell0 )
      $oXPTable.CreateInstance_3( "XPTable.Models.Cell", True, 0, 0, CreateSafeArray( "MyCheckbox1", True ), 0, $pSAEmpty, $oCell1 )
      $oXPTable.CreateInstance_3( "XPTable.Models.Cell", True, 0, 0, CreateSafeArray( "MyButton1" ), 0, $pSAEmpty, $oCell2 )
      ConsoleWrite( "IsObj( $oCell0 ) = " & IsObj( $oCell0 ) & @CRLF )
      ConsoleWrite( "IsObj( $oCell1 ) = " & IsObj( $oCell1 ) & @CRLF )
      ConsoleWrite( "IsObj( $oCell2 ) = " & IsObj( $oCell2 ) & @CRLF )
      $oTableModel.Rows.Item(0).Cells.Add( $oCell0 )
      $oTableModel.Rows.Item(0).Cells.Add( $oCell1 )
      $oTableModel.Rows.Item(0).Cells.Add( $oCell2 )
      ConsoleWrite( "Cells = " & $oTableModel.Rows.Item(0).Cells.Count() & @CRLF )

      $oTable.Left() = 10
      $oTable.Top() = 10
      $oTable.Width() = 300
      $oTable.Height() = 200

      Local $hTable = $oTable.Handle()
      Local $hGui = GUICreate( "XPTable", 320, 220 )
      _WinAPI_SetParent( $hTable, $hGui )
      GUISetState()
      Do
      Until GUIGetMsg() = -3 ; $GUI_EVENT_CLOSE
    EndIf

  EndIf

  DllClose($hMSCorEE)
EndFunc

Func CreateSafeArray( $string, $bool = Default )
  Local $tSafeArrayBound = DllStructCreate( $tagSAFEARRAYBOUND )
  Local $pSafeArray, $pSafeArrayData
  DllStructSetData( $tSafeArrayBound, "cElements", $bool = Default ? 1 : 2 )
  DllStructSetData( $tSafeArrayBound, "lLbound", 0 )
  $pSafeArray =  SafeArrayCreate( $VT_VARIANT, 1, $tSafeArrayBound )
  SafeArrayAccessData( $pSafeArray, $pSafeArrayData )
  DllStructSetData( DllStructCreate( "word", $pSafeArrayData ), 1, $VT_BSTR )
  DllStructSetData( DllStructCreate( "ptr", $pSafeArrayData + 8 ), 1, SysAllocString( $string ) )
  If $bool Then
    $pSafeArrayData += @AutoItX64 ? 24 : 16
    DllStructSetData( DllStructCreate( "word", $pSafeArrayData ), 1, $VT_BOOL )
    DllStructSetData( DllStructCreate( "short", $pSafeArrayData + 8 ), 1, $bool )
  EndIf
  SafeArrayUnaccessData( $pSafeArray )
  Return $pSafeArray
EndFunc

Since you need Variant and SafeArray UDFs I've included all code in the zip. Run tst00.au3 in SciTE. You still have to download XPTable.dll. See post 59.

Danyfirex you are right. It was easy.

XPTable.7z

Edited by LarsJ
Added XPTable.dll to zip file
Link to comment
Share on other sites

4 hours ago, LarsJ said:

example (tst00.ahk about XPTable.dll assembly) is translated

>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Owner\Downloads\XPTable\tst00.au3
+>19:55:20 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Owner\Downloads\XPTable\tst00.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
>oClrHost: 1
>pCLRRuntimeInfo: 0x00B9EC38
>oCLRRuntimeInfo: 1
>IsLoadable: True
>pCLRRuntimeHost: 0x00BA1378
>oCLRRuntimeHost: 1
IsObj( $oCorRuntimeHost ) = 1
$pAppDomain = 0x00AC002C
IsObj( $oAppDomain ) = 1
$pType = 0x00AC0018
IsObj( $oType ) = 1
$pAssembly = 0x00ACFFD0
IsObj( $oAssembly ) = 1
$pAssemblyType = 0x00ACFF98
IsObj( $oAssemblyType ) = 1
$pXPTable = 0x00000000
IsObj( $oXPTable ) = 0
"C:\Users\Owner\Downloads\XPTable\tst00.au3" (457) : ==> Variable must be of type "Object".:
$oXPTable.CreateInstance_2( "XPTable.Models.Table", True, $oTable )
$oXPTable^ ERROR
->19:55:20 AutoIt3.exe ended.rc:1
+>19:55:20 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 0.5215

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I've tested the code on Win 7/10 32/64 bit. Works in all four cases.

Output in SciTE:

>oClrHost: 1
>pCLRRuntimeInfo: 0x007A2548
>oCLRRuntimeInfo: 1
>IsLoadable: True
>pCLRRuntimeHost: 0x00766218
>oCLRRuntimeHost: 1
IsObj( $oCorRuntimeHost ) = 1
$pAppDomain = 0x006E002C
IsObj( $oAppDomain ) = 1
$pType = 0x006E0018
IsObj( $oType ) = 1
$pAssembly = 0x006EFFD0
IsObj( $oAssembly ) = 1
$pAssemblyType = 0x006EFF98
IsObj( $oAssemblyType ) = 1
$pXPTable = 0x006EFF50
IsObj( $oXPTable ) = 1
IsObj( $oTable ) = 1
IsObj( $oColumnModel ) = 1
IsObj( $oTableModel ) = 1
IsObj( $oColumn0 ) = 1
IsObj( $oColumn1 ) = 1
IsObj( $oColumn2 ) = 1
VisibleColumnCount = 3
IsObj( $oRow ) = 1
Rows = 1
IsObj( $oCell0 ) = 1
IsObj( $oCell1 ) = 1
IsObj( $oCell2 ) = 1
Cells = 3

I've added XPTable.dll to the zip in post 62. Try again.

Link to comment
Share on other sites

The second AutoHotkey example (C-sharp code) is translated:

;#AutoIt3Wrapper_UseX64=y

#include "SafeArray.au3"
#include "Variant.au3"

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

Func _WinAPI_SetParent($hWndChild, $hWndParent)
  Local $aResult = DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $hWndParent)
  If @error Then Return SetError(@error, @extended, 0)

  Return $aResult[0]
EndFunc   ;==>_WinAPI_SetParent

Global Const $S_OK = 0

Global Const $sCLSID_CLRMetaHost = "{9280188d-0e8e-4867-b30c-7fa83884e8de}"
Global Const $tCLSID_CLRMetaHost = _WinAPI_CLSIDFromString($sCLSID_CLRMetaHost)
Global Const $sIID_ICLRMetaHost = "{d332db9e-b9b3-4125-8207-a14884f53216}"
Global Const $tIID_ICLRMetaHost = _WinAPI_CLSIDFromString($sIID_ICLRMetaHost)
Global Const $sTag_ICLRMetaHost = _
  "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 $sIID_ICLRRuntimeInfo = "{BD39D1D2-BA2F-486a-89B0-B4B0CB466891}"
Global Const $tIID_ICLRRuntimeInfo = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeInfo)
Global Const $sTag_ICLRRuntimeInfo = _
  "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 $sCLSID_CLRRuntimeHost = "{90F1A06E-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $tCLSID_CLRRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CLRRuntimeHost)
Global Const $sIID_ICLRRuntimeHost = "{90F1A06C-7712-4762-86B5-7A5EBA6BDB02}"
Global Const $tIID_ICLRRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICLRRuntimeHost)
Global Const $sTag_ICLRRuntimeHost = _
  "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 $sCLSID_CorRuntimeHost = "{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}"
Global Const $tCLSID_CorRuntimeHost = _WinAPI_CLSIDFromString($sCLSID_CorRuntimeHost)
Global Const $sIID_ICorRuntimeHost = "{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}"
Global Const $tIID_ICorRuntimeHost = _WinAPI_CLSIDFromString($sIID_ICorRuntimeHost)
Global 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();"

Global Const $sIID_IAppDomain = "{05F696DC-2B29-3663-AD8B-C4389CF2A713}"
Global Const $sTag_IAppDomain = _
  "GetTypeInfoCount hresult();" & _
  "GetTypeInfo hresult();" & _
  "GetIDsOfNames hresult();" & _
  "Invoke hresult();" & _
  "get_ToString hresult();" & _
  "Equals hresult();" & _
  "GetHashCode hresult();" & _
  "GetType hresult(ptr*);" & _
  "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(bstr;bstr;object*);" & _
  "CreateInstanceFrom hresult();" & _
  "CreateInstance_2 hresult();" & _
  "CreateInstanceFrom_2 hresult();" & _
  "CreateInstance_3 hresult();" & _
  "CreateInstanceFrom_3 hresult();" & _
  "Load hresult();" & _
  "Load_2 hresult();" & _
  "Load_3 hresult();" & _
  "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 ) = 0; hresult();" & _
  "SetShadowCopyPath hresult();" & _
  "ClearShadowCopyPath ) = 0; hresult();" & _
  "SetCachePath hresult();" & _
  "SetData hresult();" & _
  "GetData hresult();" & _
  "SetAppDomainPolicy hresult();" & _
  "SetThreadPrincipal hresult();" & _
  "SetPrincipalPolicy hresult();" & _
  "DoCallBack hresult();" & _
  "get_DynamicDirectory hresult();"

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

; InvokeMember, InvokeMember_2, InvokeMember_3
Global Const $BindingFlags_Default = 0x0000
Global Const $BindingFlags_IgnoreCase = 0x0001
Global Const $BindingFlags_DeclaredOnly = 0x0002
Global Const $BindingFlags_Instance = 0x0004
Global Const $BindingFlags_Static = 0x0008
Global Const $BindingFlags_Public = 0x0010
Global Const $BindingFlags_NonPublic = 0x0020
Global Const $BindingFlags_FlattenHierarchy = 0x0040
Global Const $BindingFlags_InvokeMethod = 0x0100
Global Const $BindingFlags_CreateInstance = 0x0200
Global Const $BindingFlags_GetField = 0x0400
Global Const $BindingFlags_SetField = 0x0800
Global Const $BindingFlags_GetProperty = 0x1000
Global Const $BindingFlags_SetProperty = 0x2000
Global Const $BindingFlags_PutDispProperty = 0x4000
Global Const $BindingFlags_PutRefDispProperty = 0x8000
Global Const $BindingFlags_ExactBinding = 0x00010000
Global Const $BindingFlags_SuppressChangeType = 0x00020000
Global Const $BindingFlags_OptionalParamBinding = 0x00040000
Global Const $BindingFlags_IgnoreReturn = 0x01000000

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();" & _
  "Equals hresult();" & _
  "GetHashCode hresult();" & _
  "GetType hresult(ptr*);" & _
  "get_CodeBase hresult();" & _
  "get_EscapedCodeBase hresult();" & _
  "GetName hresult();" & _
  "GetName_2 hresult();" & _
  "get_FullName hresult();" & _
  "get_EntryPoint hresult();" & _
  "GetType_2 hresult();" & _
  "GetType_3 hresult();" & _
  "GetExportedTypes hresult();" & _
  "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();"


Example()

Func Example()
  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_ICLRMetaHost)
    ConsoleWrite(">oClrHost: " & IsObj($oClrHost) & @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_ICLRRuntimeInfo)
    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_ICLRRuntimeHost)
      ConsoleWrite(">oCLRRuntimeHost: " & IsObj($oCLRRuntimeHost) & @CRLF)

      $oCLRRuntimeHost.Start()

      ;Local $iRet = 0
      ;$oCLRRuntimeHost.ExecuteInDefaultAppDomain(@ScriptDir & "\C#Library.dll", "ClassLibraryDemo.ClassDemo", "NetMsgBox", "AutoIt Rocks!!! " & @CRLF & "Danyfirex does too lol!!!", $iRet)
      ;ConsoleWrite(">Ret: " & $iRet & @CRLF)

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

      ; tst01.ahk
      ; CLR_LoadLibrary
      ; assembly := typeofAssembly.InvokeMember_3("LoadWithPartialName", 0x158, null, null, args)

      Local $pAppDomain = 0
      $oCorRuntimeHost.GetDefaultDomain($pAppDomain)
      ConsoleWrite("$pAppDomain = " & Ptr($pAppDomain) & @CRLF)

      Local $oAppDomain = ObjCreateInterface($pAppDomain, $sIID_IAppDomain, $sTag_IAppDomain)
      ConsoleWrite("IsObj( $oAppDomain ) = " & IsObj($oAppDomain) & @CRLF)

      Local $pType
      $oAppDomain.GetType( $pType )
      ConsoleWrite( "$pType = " & Ptr( $pType ) & @CRLF )

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

      Local $pAssembly
      $oType.get_Assembly( $pAssembly )
      ConsoleWrite( "$pAssembly = " & Ptr( $pAssembly ) & @CRLF )

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

      Local $pAssemblyType
      $oAssembly.GetType( $pAssemblyType )
      ConsoleWrite( "$pAssemblyType = " & Ptr( $pAssemblyType ) & @CRLF )

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

      ; args := ComObjArray(0xC, 1),  args[0] := "System"
      Local $tSafeArrayBound = DllStructCreate( $tagSAFEARRAYBOUND )
      Local $pSafeArray, $pSafeArrayData
      DllStructSetData( $tSafeArrayBound, "cElements", 1 )
      DllStructSetData( $tSafeArrayBound, "lLbound", 0 )
      $pSafeArray =  SafeArrayCreate( $VT_VARIANT, 1, $tSafeArrayBound )
      SafeArrayAccessData( $pSafeArray, $pSafeArrayData )
      DllStructSetData( DllStructCreate( "word", $pSafeArrayData ), 1, $VT_BSTR )
      DllStructSetData( DllStructCreate( "ptr", $pSafeArrayData + 8 ), 1, SysAllocString( "System" ) )
      SafeArrayUnaccessData( $pSafeArray )

      Local $pAsmProvider
      $oAssemblyType.InvokeMember_3( "LoadWithPartialName", 0x158, 0, 0, $pSafeArray, $pAsmProvider )
      ; 0x158 = $BindingFlags_Static + $BindingFlags_Public + $BindingFlags_FlattenHierarchy + $BindingFlags_InvokeMethod
      ConsoleWrite( "$pAsmProvider = " & Ptr( $pAsmProvider ) & @CRLF )

      Local $oAsmProvider = ObjCreateInterface( $pAsmProvider, $sIID_IAssembly, $sTag_IAssembly )
      ConsoleWrite( "IsObj( $oAsmProvider ) = " & IsObj( $oAsmProvider ) & @CRLF )

      ; codeProvider := asmProvider.CreateInstance("Microsoft.CSharp.CSharpCodeProvider")
      Local $oCodeProvider
      $oAsmProvider.CreateInstance( "Microsoft.CSharp.CSharpCodeProvider", $oCodeProvider )
      ConsoleWrite( "IsObj( $oCodeProvider ) = " & IsObj( $oCodeProvider ) & @CRLF )

      ; codeCompiler := codeProvider.CreateCompiler()
      Local $oCodeCompiler = $oCodeProvider.CreateCompiler()
      ConsoleWrite( "IsObj( $oCodeCompiler ) = " & IsObj( $oCodeCompiler ) & @CRLF )

      Local $oAsmSystem = $oAsmProvider

      ; Convert | delimited list of references into an array.
      ; References = "System.dll | System.Management.dll | System.Windows.Forms.dll"
      ; StringSplit, Refs, References, |, %A_Space%%A_Tab%
      ; aRefs := ComObjArray(8, Refs0)
      ; Loop % Refs0
      ;   aRefs[A_Index-1] := Refs%A_Index%
      Local $tSafeArray1Bound = DllStructCreate( $tagSAFEARRAYBOUND )
      Local $pSafeArray1, $pSafeArray1Data
      DllStructSetData( $tSafeArray1Bound, "cElements", 3 )
      DllStructSetData( $tSafeArray1Bound, "lLbound", 0 )
      $pSafeArray1 =  SafeArrayCreate( $VT_BSTR, 1, $tSafeArray1Bound )
      SafeArrayAccessData( $pSafeArray1, $pSafeArray1Data )
      DllStructSetData( DllStructCreate( "ptr", $pSafeArray1Data ), 1, SysAllocString( "System.dll" ) )
      $pSafeArray1Data += @AutoItX64 ? 8 : 4
      DllStructSetData( DllStructCreate( "ptr", $pSafeArray1Data ), 1, SysAllocString( "System.Management.dll" ) )
      $pSafeArray1Data += @AutoItX64 ? 8 : 4
      DllStructSetData( DllStructCreate( "ptr", $pSafeArray1Data ), 1, SysAllocString( "System.Windows.Forms.dll" ) )
      SafeArrayUnaccessData( $pSafeArray1 )

      ; prms := CLR_CreateObject(asmSystem, "System.CodeDom.Compiler.CompilerParameters", aRefs)

      ; args := ComObjArray(0xC, 1),  args[0] := "XPTable.dll"
      Local $tSafeArray2Bound = DllStructCreate( $tagSAFEARRAYBOUND )
      Local $pSafeArray2, $pSafeArray2Data
      DllStructSetData( $tSafeArray2Bound, "cElements", 1 )
      DllStructSetData( $tSafeArray2Bound, "lLbound", 0 )
      $pSafeArray2 =  SafeArrayCreate( $VT_VARIANT, 1, $tSafeArray2Bound )
      SafeArrayAccessData( $pSafeArray2, $pSafeArray2Data )
      DllStructSetData( DllStructCreate( "word", $pSafeArray2Data ), 1, $VT_BSTR + $VT_ARRAY )
      DllStructSetData( DllStructCreate( "ptr", $pSafeArray2Data + 8 ), 1, $pSafeArray1 )
      SafeArrayUnaccessData( $pSafeArray2 )

      ; static Array_Empty := ComObjArray(0xC,0), null := ComObject(13,0)
      Local $pSAEmpty, $tSAB = DllStructCreate( $tagSAFEARRAYBOUND )
      DllStructSetData( $tSAB, "cElements", 0 )
      DllStructSetData( $tSAB, "lLbound", 0 )
      $pSAEmpty =  SafeArrayCreate( $VT_VARIANT, 0, $tSAB )

      Local $oPrms
      $oAsmSystem.CreateInstance_3( "System.CodeDom.Compiler.CompilerParameters", True, 0, 0, $pSafeArray2, 0, $pSAEmpty, $oPrms )
      ConsoleWrite( "IsObj( $oPrms ) = " & IsObj( $oPrms ) & @CRLF )

      Local $sCode = FileRead( "Code.cs" )
      ConsoleWrite( "$sCode = " & @CRLF & $sCode )
  
      ; Compile!
      ; compilerRes := codeCompiler.CompileAssemblyFromSource(prms, Code)
      Local $oCompilerRes = $oCodeCompiler.CompileAssemblyFromSource( $oPrms, $sCode )
      ConsoleWrite( "IsObj( $oCompilerRes ) = " & IsObj( $oCompilerRes ) & @CRLF )

      Local $pCodeAssembly = $oCompilerRes.CompiledAssembly()
      ConsoleWrite( "$pCodeAssembly = " & Ptr( $pCodeAssembly ) & @CRLF )

      Local $oCodeAssembly = ObjCreateInterface( $pCodeAssembly, $sIID_IAssembly, $sTag_IAssembly )
      ConsoleWrite( "IsObj( $oCodeAssembly ) = " & IsObj( $oCodeAssembly ) & @CRLF )

      Local $oCodeObject
      $oCodeAssembly.CreateInstance_2( "Foo", True, $oCodeObject )
      ConsoleWrite( "IsObj( $oCodeObject ) = " & IsObj( $oCodeObject ) & @CRLF )

      Local $sKram = $oCodeObject.Test( "Win32_Processor" )
      $sKram = StringReplace( $sKram, "/n", @CRLF )
      MsgBox( 0, "", $sKram )
    EndIf

  EndIf

  DllClose($hMSCorEE)
EndFunc

Since you need Variant and SafeArray UDFs I've included all code in the zip. Run tst01.au3 in SciTE.

Output in SciTE:

>oClrHost: 1
>pCLRRuntimeInfo: 0x008F9980
>oCLRRuntimeInfo: 1
>IsLoadable: True
>pCLRRuntimeHost: 0x0088C768
>oCLRRuntimeHost: 1
IsObj( $oCorRuntimeHost ) = 1
$pAppDomain = 0x006D002C
IsObj( $oAppDomain ) = 1
$pType = 0x006D0018
IsObj( $oType ) = 1
$pAssembly = 0x006DFFD0
IsObj( $oAssembly ) = 1
$pAssemblyType = 0x006DFF98
IsObj( $oAssemblyType ) = 1
$pAsmProvider = 0x006DFF50
IsObj( $oAsmProvider ) = 1
IsObj( $oCodeProvider ) = 1
IsObj( $oCodeCompiler ) = 1
IsObj( $oPrms ) = 1
$sCode = 
using System.Windows.Forms;
using System.Management;
using System;
class Foo {
  public string Test(string geraet) {
    string Tabelle = " ";
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + geraet);
    ManagementObjectCollection irgendwas = searcher.Get();
    foreach (ManagementObject mo in irgendwas) {
      foreach (PropertyData prop in mo.Properties) {
        Tabelle = Tabelle + "/n" + prop.Name + ": " + prop.Value;
      }
    }
    return Tabelle;
  }
}
IsObj( $oCompilerRes ) = 1
$pCodeAssembly = 0x006DFE90
IsObj( $oCodeAssembly ) = 1
IsObj( $oCodeObject ) = 1

CScode.7z

Edited by LarsJ
Link to comment
Share on other sites

Remove _WinAPI_SetParent haha.

 

Nice Larsj. just Build the UDF haha You're so fast. it seems to be you have a lot of free time. lol. (I prefer watch the walking dead haha)

Edit:  Working great in Windows 10 x64. Compiled x86 & x64

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Link to comment
Share on other sites

Hello Here is a small UDF wrapper(It's pretty funny to call it UDF. it's more a start to build  one) 

It need to be clean add error checking remove comments create functions help etc.. etc......... But I really don't have enough time to do it maybe someone  can do it.

Evething is gathered from previous codes. I added some examples all in a zip. 

 

CLR.zip

Updated-1:

CLR.zip

Updated-2:

CLR.zip

Updated-3

CLR.zip

Examples:

;~ _Example1() ;C# & VB Messagebox
;~ _Example2() ;C# Create Executable
;~ _Example3() ;C#Return String from Class Method
;~ _Example4() ;XPTable Example
;~ _Example5() ;A MessageBox Using System.Windows.Forms.MessageBox
;~ _Example6() ;WebClient.DownloadString  Using System.Net.WebClient
;~ _Example7() ;Form  Using System.Windows.Forms.Form
;~ _Example8() ;Stack Using System.Collections.Generic.Stack
;~ _Example9() ;File.ReadAllText Using System.IO
;~ _Example10() ;ArrayList Using System.Collections.ArrayList

 

Saludos

Edited by Danyfirex
Update
Link to comment
Share on other sites

HI Larsj,

These are 2 really sweet working examples indeed !

You realy get the swing of it.

 And you get to add your SafeArray work into play as well on which you have been working hard too :graduated:

If we compare the AHK features, we are nearly there I guess :

  • Load the Common Language Runtime into the script's process. => DONE
  • Load .NET assemblies (dll files) by full name, partial name, or path. => DONE
  • Instantiate objects and call instance methods or properties.
  • Compile C# or VB code on the fly or to file. => DONE

Is there a way to call native .NET classes ...  like system.Windows.Forms.Form for example ?

 

Or is this still under investigation ? If this is working I guess we all have what is needed ... :)

Link to comment
Share on other sites

Updated CLR Example in Post #68

 

Added some examples more.

 

@ptrex added example about using  System.Windows.Forms.MessageBox

 

 

Saludos

 

Edited by Danyfirex
Typo
Link to comment
Share on other sites

Update in post #68

 

Added more examples:

;~ _Example1() ;C# & VB Messagebox
;~ _Example2() ;C# Create Executable
;~ _Example3() ;C#Return String from Class Method
;~ _Example4() ;XPTable Example
;~ _Example5() ;A MessageBox Using System.Windows.Forms.MessageBox
;~ _Example6() ;WebClient.DownloadString  Using System.Net.WebClient
;~ _Example7() ;Form  Using System.Windows.Forms.Form

 

Saludos

Link to comment
Share on other sites

Updated in Post #68

 

Added more examples:

;~ _Example1() ;C# & VB Messagebox
;~ _Example2() ;C# Create Executable
;~ _Example3() ;C#Return String from Class Method
;~ _Example4() ;XPTable Example
;~ _Example5() ;A MessageBox Using System.Windows.Forms.MessageBox
;~ _Example6() ;WebClient.DownloadString  Using System.Net.WebClient
;~ _Example7() ;Form  Using System.Windows.Forms.Form
;~ _Example8() ;Stack Using System.Collections.Generic.Stack
;~ _Example9() ;File.ReadAllText Using System.IO
;~ _Example10() ;ArrayList Using System.Collections.ArrayList

 

Saludos

Link to comment
Share on other sites

Basically it works on my system except for xpTable (not sure why), Win 10 / 64 bits

example 7 works but ...

>oClrHost: 1
>pCLRRuntimeInfo: 0x0000026667E28810
>oCLRRuntimeInfo: 1
>IsLoadable: True
>pCLRRuntimeHost: 0x0000026667C4FA80
>oCLRRuntimeHost: 1
IsObj( $oCorRuntimeHost ) = 1
$pAppDomain = 0x0000026668770018
IsObj( $oAppDomain ) = 1
$pType = 0x000002666877FFB0
IsObj( $oType ) = 1
$pAssembly = 0x000002666877FEA0
IsObj( $oAssembly ) = 1
$pAssemblyType = 0x000002666877FDB0
IsObj( $oAssemblyType ) = 1
-$pObject = 0x0000000000000000
-$pAsmProvider = 0x000002666877FC20
-IsObj( $oObject ) = 1
!$oAssembly: 1
!$oForm: 1
$oForm Handle: 4656984

-$pObject = 0x0000000000000000
-$pAsmProvider = 0x000002666877FC20
-IsObj( $oObject ) = 1

Playing around with this extending example 7

#Region dynamic controls
;~  $oCol=$oForm.Controls
;~  ConsoleWrite("!$oCol: " & IsObj($oCol) & @CRLF)

;~  Local $oBtn= _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button")
;~  ConsoleWrite("!$oBtn " & IsObj($oBtn) & @CRLF)

;~  Local $oText= _CRL_CreateObject($oAssembly, "System.Windows.Forms.TextBox")
;~  ConsoleWrite("!$oText: " & IsObj($oText) & @CRLF)

;~  $ocol.Add($oBtn)
;~  $ocol.Add($oText)

#EndRegion

 

Link to comment
Share on other sites

XPTable should work compiling for x86. for x64 you need x64 dll version.

 

Saludos

Link to comment
Share on other sites

Example 1-10 is working. (on example with xptable i had to set my path to the dll)

_CRL_CreateObject( has small typo in the beginning _CRL instead of _CLR

on example 7 i tried to extend (it looks so simple but unfortunately not working how I expect it to be working)

#Region dynamic controls
;~  $oCol=$oForm.Controls
;~  ConsoleWrite("!$oCol: " & IsObj($oCol) & @CRLF)

;~  Local $oBtn= _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button")
;~  ConsoleWrite("!$oBtn " & IsObj($oBtn) & @CRLF)

;~  Local $oText= _CRL_CreateObject($oAssembly, "System.Windows.Forms.TextBox")
;~  ConsoleWrite("!$oText: " & IsObj($oText) & @CRLF)

;~  $ocol.Add($oBtn)
;~  $ocol.Add($oText)

#EndRegion

 

Link to comment
Share on other sites

any reference on how to deal with safearrays and AutoIT?  (read the post(s) from LarsJ in the forums by searching for SafeArray)

SAFEARRAY *pAssemblyArray = NULL;
HRESULT hr = pAppDomain->GetAssemblies(&pAssemblyArray);

just trying to get the count of loaded assemblies (to later just write out which ones are automatically loaded)

Func _Example()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    local $result

    local $oDomain
    $oDomain=_CLR_GetDefaultDomain()
    ConsoleWrite("$oDomain: " & IsObj($oDomain) & @CRLF)

    local $pVals=0
    ; Declare empty SafeArray
    local $pAssemblyArray=Null
    local $pAssemblyArray=$oDomain.getAssemblies()

; Access the safearray
    $result=SafeArrayAccessData($pAssemblyArray,$pVals)
    consolewrite("result " & $result & @CRLF)


    local $iCount=-1
    SafeArrayGetUBound($pAssemblyArray, 1, $iCount)
    consoleWrite("Array elements" & $iCount & @CRLF)
    SafeArrayUnAccessData($pAssemblyArray)
EndFunc   ;==>_Example
Link to comment
Share on other sites

Map implementation of Hashtable.
https://msdn.microsoft.com/en-us/library/system.collections.hashtable(v=vs.110).aspx

Func _Example()
    Local $oAssembly = _CLR_LoadLibrary("mscorlib")
    ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)
    Local $oClouds = _CRL_CreateObject($oAssembly, "System.Collections.Hashtable")
    ConsoleWrite("!$oHash: " & IsObj($oClouds) & @CRLF)
        $oClouds.Add("Cirrus", "Castellanus");
        $oClouds.Add("Cirrocumulus", "Stratiformis");
        $oClouds.Add("Altostratus", "Radiatus");
        $oClouds.Add("Stratocumulus", "Perlucidus");
        $oClouds.Add("Stratus", "Fractus");
        $oClouds.Add("Nimbostratus", "Pannus");
        $oClouds.Add("Cumulus", "Humilis");
        $oClouds.Add("Cumulonimbus", "Incus");

    local $iCloudCount=$oClouds.count
    consolewrite("Clouds added " & $iCloudCount & @CRLF)
    consolewrite("It contains Fractus " & $oClouds.containsvalue("Fractus") & @CRLF)


EndFunc   ;==>_Example

 

Link to comment
Share on other sites

This is how I got the button to show. But it's not quite as it should work in .NET ?

;~  #AutoIt3Wrapper_UseX64=y

#include "CLR.Au3"
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_ExampleTest() ;Form  Using System.Windows.Forms.Form

Func _ExampleTest()
    Local $oAssembly = _CLR_LoadLibrary("System.Windows.Forms")
    ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF)
    Local $oForm = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Form")
    ConsoleWrite("!$oForm: " & IsObj($oForm) & @CRLF)
    $oForm.Text = "Form From Net - AutoIt Rocks"
    $oForm.Width = 800
    $oForm.Height = 400

    Local $oButton1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button")
    $oButton1.Text = "button"
    $oButton1.Width = 60
    $oButton1.Height = 30

    Local $oDrawing = _CLR_LoadLibrary("System.Drawing")
;~  Local $oDraw = _CRL_CreateObject($oDrawing, "System.Drawing.point")

    ConsoleWrite("!$oDrawing: " & IsObj($oDrawing) & @CRLF)
    ;$oButton1.location = $oDrawing(60,15)

    ConsoleWrite("!$oButton1: " & IsObj($oButton1) & @CRLF)
    ConsoleWrite($oButton1.handle & @CRLF)

;~ $oForm.Controls.Add($oButton1)
    _WinAPI_SetParent($oButton1.handle, $oForm.Handle)

    $oForm.ShowDialog()

    ConsoleWrite("$oForm Handle: " & $oForm.Handle & @CRLF)

    $oForm.Dispose()
EndFunc   ;==>_ExampleTest

So I guess we are missing some things to make it all work properly ?

Could not get the positioning to work either ?

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