Jump to content

ITypeInfo to extract information about the characteristics and capabilities of objects from type libraries

Recommended Posts

I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt

Turns out it was pretty easy.

A Few Notes:

CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.

The Object must have IDispatch exposed (ITypeInfo is derivative)

Its Just a proof of concept Run with it but don't carry scissors


;Bilgus 2018
#include <WinAPI.au3>

; === IDispatch interface ===

; http://msdn.microsoft.com/en-us/library/windows/desktop/ms221608(v=vs.85).aspx

; Exposes objects, methods and properties to programming tools and other applications that support Automation.
; COM components implement the IDispatch interface to enable access by Automation clients, such as Visual Basic.

Global Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
Global Const $dtag_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.

; === ITypeInfo interface ===


;Used for reading information about objects.
;For example, an object browser tool can use ITypeInfo to extract information about the characteristics and capabilities of objects from type libraries

Global Const $sIID_ITypeInfo = "{00020401-0000-0000-C000-000000000046}"
Global Const $tRIID_ITypeInfo = _WinAPI_GUIDFromString($sIID_ITypeInfo)

Global Const $dtag_ITypeInfo = _
        "GetTypeAttr hresult(ptr*);" & _ ;Retrieves a TYPEATTR structure that contains the attributes of the type description
        "GetTypeComp hresult(ptr*);" & _ ;Retrieves the ITypeComp interface for the type description, which enables a client compiler to bind to the type description's members
        "GetFuncDesc hresult(uint;ptr*;);" & _ ;Retrieves the FUNCDESC structure that contains information about a specified function
        "GetVarDesc hresult(uint;ptr*);" & _ ;Retrieves a VARDESC structure that describes the specified variable
        "GetNames hresult(long;ptr;uint;uint*);" & _ ;Retrieves the variable with the specified member ID or the name of the property or method and the parameters that correspond to the specified function ID
        "GetRefTypeOfImplType hresult(dword;ptr);" & _ ;If a type description describes a COM class, it retrieves the type description of the implemented interface types
        "GetImplTypeFlags hresult(uint;int*);" & _ ;Retrieves the IMPLTYPEFLAGS enumeration for one implemented interface or base interface in a type description
        "GetIDsOfNames hresult(ptr;uint;long*);" & _ ;Maps between member names and member IDs, and parameter names and parameter IDs
        "Invoke hresult(ptr;long;word;ptr;ptr;ptr;uint*);" & _ ;Invokes a method, or accesses a property of an object, that implements the interface described by the type description
        "GetDocumentation hresult(long;ptr;ptr;dword*;ptr);" & _ ;Retrieves the documentation string, the complete Help file name and path, and the context ID for the Help topic for a specified type description
        "GetDllEntry hresult(long;int;ptr;ptr;word*);" & _ ;Retrieves a description or specification of an entry point for a function in a DLL
        "GetRefTypeInfo hresult(dword;ptr*);" & _ ;If a type description references other type descriptions, it retrieves the referenced type descriptions
        "AddressOfMember hresult(long;int;ptr);" & _ ;Retrieves the addresses of static functions or variables, such as those defined in a DLL
        "CreateInstance hresult(ptr;clsid;ptr);" & _ ;Creates a new instance of a type that describes a component object class (coclass)
        "GetMops hresult(long;ptr);" & _ ;Retrieves marshaling information
        "GetContainingTypeLib hresult(ptr;uint*);" & _ ;Retrieves the containing type library and the index of the type description within that type library
        "ReleaseTypeAttr none(ptr);" & _ ;Releases a TYPEATTR previously returned by ITypeInfo::GetTypeAttr
        "ReleaseFuncDesc none(ptr);" & _ ;Releases a FUNCDESC previously returned by ITypeInfo::GetFuncDesc
        "ReleaseVarDesc none(ptr);" ;Releases a VARDESC previously returned by ITypeInfo::GetVarDesc

Global Enum $VT_EMPTY = 0, $VT_NULL = 1, $VT_I2 = 2, $VT_I4 = 3, $VT_R4 = 4, _
        $VT_R8 = 5, $VT_CY = 6, $VT_DATE = 7, $VT_BSTR = 8, $VT_DISPATCH = 9, _
        $VT_ERROR = 10, $VT_BOOL = 11, $VT_VARIANT = 12, $VT_UNKNOWN = 13, _
        $VT_DECIMAL = 14, $VT_I1 = 16, $VT_UI1 = 17, $VT_UI2 = 18, $VT_UI4 = 19, _
        $VT_I8 = 20, $VT_UI8 = 21, $VT_INT = 22, $VT_UINT = 23, $VT_VOID = 24, _
        $VT_HRESULT = 25, $VT_PTR = 26, $VT_SAFEARRAY = 27, $VT_CARRAY = 28, _
        $VT_USERDEFINED = 29, $VT_LPSTR = 30, $VT_LPWSTR = 31, $VT_FILETIME = 64, _
        $VT_BLOB = 65, $VT_STREAM = 66, $VT_STORAGE = 67, $VT_STREAMED_OBJECT = 68, _
        $VT_STORED_OBJECT = 69, $VT_BLOB_OBJECT = 70, $VT_CF = 71, $VT_CLSID = 72, _
        $VT_VECTOR = 0x1000, $VT_ARRAY = 0x2000, $VT_BYREF = 0x4000, $VT_RESERVED = 0x8000, _
        $VT_ILLEGAL = 0xffff, $VT_ILLEGALMASKED = 0xfff, $VT_TYPEMASK = 0xfff


Global Const $tagIDLDESC = "STRUCT;dword dwRESERVEDIDL;ushort wIDLFlags;ENDSTRUCT;"

Global Const $tagTYPEDESC = "STRUCT;ptr lpdesc;ushort vt;ENDSTRUCT;"
Global Const $tagTYPEDESC_HREF = "dword hreftype;" ; &UNION^

Global Const $tagPARAMDESC = "STRUCT;ptr pparamdescex;ushort wParamFlags;ENDSTRUCT;"

Global Const $SIZEOF_tagElemDesc = DllStructGetSize(DllStructCreate($tagELEMDESC))

Global Const $tagTYPEATTR = _
        "STRUCT;" & _
        $tagGUID & _
        ";dword lcid;" & _
        "dword dwReserved;" & _
        "long memidConstructor;" & _
        "long memidDestructor;" & _
        "ptr lpstrSchema;" & _
        "ulong cbSizeInstance;" & _
        "int typekind;" & _
        "word cFuncs;" & _
        "word cVars;" & _
        "word cImplTypes;" & _
        "word cbSizeVft;" & _
        "word cbAlignment;" & _
        "word wTypeFlags;" & _
        "word wMajorVerNum;" & _
        "word wMinorVerNum;" & _
        $tagTYPEDESC & _
        $tagIDLDESC & _

Global Const $tagFUNCDESC = _
        "STRUCT;" & _
        "long memid;" & _
        "ptr lprgscode;" & _
        "ptr lprgelemdescParam;" & _
        "int funckind;" & _
        "int invkind;" & _
        "int callconv;" & _
        "short cParams;" & _
        "short cParamsOpt;" & _
        "short oVft;" & _
        "short cScodes;" & _
        $tagELEMDESC & _
        "word wFuncFlags;" & _

Func __SysFreeString($pBstr)
    DllCall("OleAut32.dll", "NONE", "SysFreeString", "ptr", $pBstr)
    Return SetError(@error, 0, (@error = 0))
EndFunc   ;==>__SysFreeString

Func Extract_Interface_Functions(ByRef $oITypeInfo)
    ;Returns Functions and their parameters in AutoIt Array => return_type Function (int, uint*,Custom_TYPE...)
    Local $iResult, $iCtFuncs
    Local $aFunctions[0]

    Local $tTypeAttr = Get_ITypeInfo_Attr($oITypeInfo)

    If (Not @error) Then
        $iCtFuncs = DllStructGetData($tTypeAttr, "cFuncs") ;How many functions
        ReDim $aFunctions[$iCtFuncs] ;Init our Function array

        $oITypeInfo.ReleaseTypeAttr(DllStructGetPtr($tTypeAttr)) ;Important! Release TYPEATTR

    For $i = 0 To $iCtFuncs - 1
        Local $sReturnType, $sFunctionName, $sParameterTypes
        Local $pFuncDesc, $sPrefix

        $iResult = $oITypeInfo.GetFuncDesc($i, $pFuncDesc) ;Get Pointer to FUNCDESC
        If (Not $iResult) And $pFuncDesc Then
            Local $tFuncDesc = DllStructCreate($tagFUNCDESC, $pFuncDesc)
            Local $iCtParams = DllStructGetData($tFuncDesc, "cParams") ;How many parameters (arguments)

            $sFunctionName = Get_FunctionName(DllStructGetData($tFuncDesc, "memid"), $oITypeInfo) ;Member ID identifies function

            If (Not @error) Then
                $sReturnType = StringifyTypeDesc(DllStructGetPtr($tFuncDesc, "lpdesc"), $oITypeInfo) ;Return Type

                If DllStructGetData($tFuncDesc, "invkind") = 2 Then
                    $sPrefix = "get_"
                ElseIf DllStructGetData($tFuncDesc, "invkind") = 4 Then
                    $sPrefix = "set_"
                    $sPrefix = ""

                $sFunctionName = $sPrefix & $sFunctionName ;Add get or set on getters/setters

                $sParameterTypes = Get_ParameterList(DllStructGetData($tFuncDesc, "lprgelemdescParam"), $iCtParams, $oITypeInfo)

                $aFunctions[$i] = $sReturnType & " " & $sFunctionName & " (" & $sParameterTypes & ")"

            $oITypeInfo.ReleaseFuncDesc($pFuncDesc) ;Important! Release FUNCDESC
            ConsoleWriteError("Error Retrieving Function Description: " & Hex($iResult) & @CRLF)
    Return $aFunctions
EndFunc   ;==>Extract_Interface_Functions

Func Get_FunctionName($iMemberId, $oITypeInfo)
    Local $iError, $sFunctionName, $iResult

    Local $aWstrName = WstrCreate_pp() ;**WSTR
    Local $ppWstr = WstrGetPointer_pp($aWstrName)
    If (Not @error) Then
        $iResult = $oITypeInfo.GetDocumentation($iMemberId, $ppWstr, Null, Null, Null) ;Get the Function Name

    If (Not @error) And (Not $iResult) And $aWstrName[0] Then
        $sFunctionName = WstrExtract_pp($aWstrName) ;Function Name **WSTR
        __SysFreeString($aWstrName[0]) ; Free the BSTR
        $iError = 1
    Return SetError($iError, $iResult, $sFunctionName)
EndFunc   ;==>Get_FunctionName

Func Get_ITypeInfo_Attr(ByRef $oITypeInfo)
    ;Retrieves $tTypeAttr
    Local $tTypeAttr, $pTypeAttr, $iError

    If (Not $oITypeInfo.GetTypeAttr($pTypeAttr)) And $pTypeAttr Then
        $tTypeAttr = DllStructCreate($tagTYPEATTR, $pTypeAttr)
        $iError = 1

    Return SetError($iError, 0, $tTypeAttr)
EndFunc   ;==>Get_ITypeInfo_Attr

Func Get_ITypeInfo_Interface($oObject)
    ;Retrieves $oITypeInfo
    Local $iError, $iResult
    Local $pITypeInfo, $oITypeInfo

    While True
        If (Not IsObj($oObject)) Then
            ConsoleWrite("Init Error: Invalid Object")
            $iError = 1

        If ObjName($oObject, 1) <> "InterfaceDispatch" Then
            $oObject = ObjCreateInterface($oObject, $sIID_IDispatch, $dtag_IDispatch) ;Try To get IDispatch

        If ObjName($oObject, 1) <> "InterfaceDispatch" Then
            ConsoleWrite("Init Error: Not InterfaceDispatch based")
            $iError = 2

        $iResult = $oObject.GetTypeInfo(0, 0, $pITypeInfo)
        If $pITypeInfo Then $oITypeInfo = ObjCreateInterface($pITypeInfo, $sIID_ITypeInfo, $dtag_ITypeInfo)

        If $iResult Or (Not IsObj($oITypeInfo)) Then
            ConsoleWrite("Init Error: Failed to retrieve interface")
            $iError = 3
    Return SetError($iError, $iResult, $oITypeInfo)
EndFunc   ;==>Get_ITypeInfo_Interface

Func Get_ParameterList($pElemDesc, $iCtParams, $oITypeInfo)
    Local $sParameterTypes, $sType
    For $i = 0 To $iCtParams - 1
        ;We have to manually move the pointer by $SIZEOF_tagElemDesc for each parameter
        $sType = StringifyTypeDesc($pElemDesc + ($i * $SIZEOF_tagElemDesc), $oITypeInfo)
        If $i > 0 Then $sParameterTypes &= ", "
        $sParameterTypes &= $sType ;Param type
    Return $sParameterTypes
EndFunc   ;==>Get_ParameterList

Func StringifyCustomType($pTypeDesc_hRef, ByRef $oITypeInfo)
    ;Sean Baxter, COM Automation: Type Information (Part II)
    Local $sString = "UnknownCustomType"
    ;$tagTYPEDESC_HREF is Union with $tagTYPEDESC
    Local $tTypeDesc_hRef = DllStructCreate($tagTYPEDESC_HREF, $pTypeDesc_hRef)

    Local $iHrefType = DllStructGetData($tTypeDesc_hRef, "hreftype")

    Local $pCustTypeInfo

    While $iHrefType

        If $oITypeInfo.GetRefTypeInfo($iHrefType, $pCustTypeInfo) Or (Not $pCustTypeInfo) Then ExitLoop

        Local $oITypeInfo_Custom = ObjCreateInterface($pCustTypeInfo, $sIID_ITypeInfo, $dtag_ITypeInfo)

        If IsObj($oITypeInfo_Custom) Then
            Local $aWstrName = WstrCreate_pp() ;**WSTR

            Local $ppWstr = WstrGetPointer_pp($aWstrName)
            If @error Then ExitLoop

            If $oITypeInfo_Custom.GetDocumentation(-1, $ppWstr, Null, Null, Null) Then ExitLoop
            $sString = WstrExtract_pp($aWstrName) ;Parameter Name **WSTR

    Return $sString

EndFunc   ;==>StringifyCustomType

Func StringifyTypeDesc($pElemDesc, ByRef $oITypeInfo)
    ;Sean Baxter, COM Automation: Type Information (Part II)
    Local $tElemDesc = DllStructCreate($tagELEMDESC, $pElemDesc)

    Local $iVariantType = BitAND(DllStructGetData($tElemDesc, "vt"), 0xFFFF)

    If $iVariantType = $VT_PTR Then
        Return StringifyTypeDesc(DllStructGetData($tElemDesc, "lpdesc"), $oITypeInfo) & "*"

    ElseIf $iVariantType = $VT_SAFEARRAY Then
        Return "SAFEARRAY( " & StringifyTypeDesc(DllStructGetData($tElemDesc, "lpdesc"), $oITypeInfo) * ")"

    ElseIf $iVariantType = $VT_CARRAY Then
        ;Not Finished...Needs Sizes
        ;oss<< StringifyTypeDesc(&typeDesc->lpadesc->tdescElem, pTypeInfo);
        ;for(int dim(0); typeDesc->lpadesc->cDims; ++dim)
        ;    oss<< '['<< typeDesc->lpadesc->rgbounds[dim].lLbound<< "..."
        ;        << (typeDesc->lpadesc->rgbounds[dim].cElements +
        ;        typeDesc->lpadesc->rgbounds[dim].lLbound - 1)<< ']';
        ;return oss.str();
        MsgBox(0, "CARRAY", "Not Finished...Needs Sizes")
        Return "CARRAY " & StringifyTypeDesc(DllStructGetData($tElemDesc, "lpdesc"), $oITypeInfo)

    ElseIf $iVariantType = $VT_USERDEFINED Then
        Return StringifyCustomType($pElemDesc, $oITypeInfo)

    Return VariantArgToString($iVariantType)
EndFunc   ;==>StringifyTypeDesc

Func VariantArgToString($iVariantType)
    Switch ($iVariantType)
        ;VARIANT/VARIANTARG compatible types
        Case $VT_I2
            Return "short"
        Case $VT_I4
            Return "long"
        Case $VT_R4
            Return "float"
        Case $VT_R8
            Return "double"
        Case $VT_CY
            Return "CY"
        Case $VT_DATE
            Return "date"
        Case $VT_BSTR
            Return "bstr"
        Case $VT_DISPATCH
            Return "IDispatch*"
        Case $VT_ERROR
            Return "scode"
        Case $VT_BOOL
            Return "VARIANT_BOOL"
        Case $VT_VARIANT
            Return "variant"
        Case $VT_UNKNOWN
            Return "IUnknown*"
        Case $VT_DECIMAL
            Return "decimal"
        Case $VT_I1
            Return "char"
        Case $VT_UI1
            Return "byte"
        Case $VT_UI2
            Return "ushort"
        Case $VT_UI4
            Return "ulong"
        Case $VT_I8
            Return "int64"
        Case $VT_UI8
            Return "uint64"
        Case $VT_INT
            Return "int"
        Case $VT_UINT
            Return "UINT"
        Case $VT_VOID
            Return "void"
        Case $VT_HRESULT
            Return "hresult"
        Case $VT_LPSTR
            Return "char*"
        Case $VT_LPWSTR
            Return "wchar_t*"
        Case Else
            Return "!ERROR!"
EndFunc   ;==>VariantArgToString

Func WstrCreate_pp()
    ;Creates a Pointer to Pointer to **WSTR
    Local $aWstrObj[2]
    $aWstrObj[1] = DllStructCreate("ptr pointer")
    $aWstrObj[0] = DllStructGetPtr($aWstrObj[1])
    Return $aWstrObj
EndFunc   ;==>WstrCreate_pp

Func WstrGetPointer_pp($aWstrObj)
    Local $pPointer = 0, $iError
    If UBound($aWstrObj) = 2 Then
        $pPointer = $aWstrObj[0]

    If (Not IsPtr($pPointer)) Then
        $iError = 1
        $pPointer = 0
    Return SetError($iError, 0, $pPointer)
EndFunc   ;==>WstrGetPointer_pp

Func WstrExtract_pp($aWstrObj)
    ;Extracts Wstr from pointer to pointer to **WSTR
    Local $sString
    If UBound($aWstrObj) = 2 Then
        Local $pPointer = DllStructGetData($aWstrObj[1], "pointer")
        If IsPtr($pPointer) Then
            Local $tWstr = DllStructCreate("wchar data[65536]", $pPointer)
            $sString = DllStructGetData($tWstr, "data")
    Return $sString
EndFunc   ;==>WstrExtract_pp



#include <ITypeInfoCOM.au3>
#include <array.au3>

Global Const $sCLSID_HNetCfg_FwPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"
Global Const $sIID_INetFwPolicy2 = "{98325047-C671-4174-8D81-DEFCD3F03186}"
;Global $oObject = ObjCreateInterface($sCLSID_HNetCfg_FwPolicy2, $sIID_INetFwPolicy2, $dtag_IDispatch)

Global Const $sCLSID_HNetCfg_FwRule = "{2C5BC43E-3369-4C33-AB0C-BE9469677AF4}"
Global Const $sIID_INetFwRule2 = "{9C27C8DA-189B-4DDE-89F7-8B39A316782C}"
;Global $oObject = ObjCreateInterface($sCLSID_HNetCfg_FwRule, $sIID_INetFwRule2, $dtag_IDispatch)

Global Const $sCLSID_ShellWindows  = "{9BA05972-F6A8-11CF-A442-00A0C90A8F39}"
Global Const $sIID_IShellWindows  = "{85CB6900-4D95-11CF-960C-0080C7F4EE85}"
;Global $oObject = ObjCreateInterface($sCLSID_ShellWindows, $sIID_IShellWindows, $dtag_IDispatch)

Global Const $sCLSID_InternetExplorerV1 = "{0002DF01-0000-0000-C000-000000000046}"
Global Const $sIID_IWebBrowserApp  = "{0002DF05-0000-0000-C000-000000000046}"
;Global $oObject = ObjCreateInterface($sCLSID_InternetExplorerV1, $sIID_IWebBrowserApp, $dtag_IDispatch)

Global Const $sIID_IWebBrowser  = "{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}"
;Global $oObject = ObjCreateInterface($sCLSID_InternetExplorerV1, $sIID_IWebBrowser, $dtag_IDispatch)

Global Const $sIID_IWebBrowser2  = "{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}"
;Global $oObject = ObjCreateInterface($sCLSID_InternetExplorerV1, $sIID_IWebBrowser2, $dtag_IDispatch)

Global Const $sCLSID_MSDDSIconControl80 = "{77D2C926-7779-11D8-9070-00065B840D9C}"
Global Const $sIID_IDdsIcon = "{77D2C924-7779-11D8-9070-00065B840D9C}"
;Global $oObject = ObjCreateInterface($sCLSID_MSDDSIconControl80, $sIID_IDdsIcon, $dtag_IDispatch)

;Global $oObject = ObjCreate("HNetCfg.FwMgr")
;Global $oObject = ObjCreate("HNetCfg.FwRule")
;Global $oObject = ObjCreate("HNetCfg.FwPolicy2")
;Global $oObject = ObjCreate("shell.application")
Global $oObject = ObjCreate("MediaPlayer.MediaPlayer.1")

Local $oITypeInfo = Get_ITypeInfo_Interface($oObject)

Local $tTypeAttr = Get_ITypeInfo_Attr($oITypeInfo)

Local $aTypeAttr = TypeAttrToArray($tTypeAttr)
$oITypeInfo.ReleaseTypeAttr(DllStructGetPtr($tTypeAttr)) ;Don't Forget to free

ConsoleWrite("Type Attributes:" & @CRLF)
ConsoleWrite(PrintArray($aTypeAttr) & @CRLF)

Local $aFunctions = Extract_Interface_Functions($oITypeInfo)
ConsoleWrite("Functions:" & @CRLF)
ConsoleWrite(PrintArray($aFunctions) & @CRLF)


Func AlignmentToString($iAlignment)
    Local $sAlignment
    Switch $iAlignment
        Case 0
            $sAlignment = "64K Boundary"
        Case 1
            $sAlignment = "Normal"
        Case Else
            $sAlignment = "Align on Byte " & $iAlignment
    Return $sAlignment
EndFunc   ;==>AlignmentToString

Func PrintArray($aArr)
    $sRet = ""
    If IsArray($aArr) Then
        For $i = 0 To UBound($aArr) - 1
            $sRet &= $aArr[$i] & @CRLF
    Return $sRet
EndFunc   ;==>PrintArray

Func TypeAttrToArray($tTypeAttr)
    Local $aTypeAttr[9]
    $aTypeAttr[0] = "IId = " & _WinAPI_StringFromGUID(DllStructGetPtr($tTypeAttr, "Data1"))
    $aTypeAttr[1] = "Type Kind = " & TypeKindToString(DllStructGetData($tTypeAttr, "typekind"))
    $aTypeAttr[2] = "Functions = " & DllStructGetData($tTypeAttr, "cFuncs")
    $aTypeAttr[3] = "Variables = " & DllStructGetData($tTypeAttr, "cVars")
    $aTypeAttr[4] = "Interfaces = " & DllStructGetData($tTypeAttr, "cImplTypes")
    $aTypeAttr[5] = "Type Flags = " & TypeFlagsToString(DllStructGetData($tTypeAttr, "wTypeFlags"))
    $aTypeAttr[6] = "VTBL Sz = " & DllStructGetData($tTypeAttr, "cbSizeVft")
    $aTypeAttr[7] = "Alignment = " & AlignmentToString(DllStructGetData($tTypeAttr, "cbAlignment"))
    $aTypeAttr[8] = "Ver = " & DllStructGetData($tTypeAttr, "wMajorVerNum") & "." & DllStructGetData($tTypeAttr, "wMinorVerNum")
    Return $aTypeAttr
EndFunc   ;==>TypeAttrToArray

Func TypeFlagsToString($iTypeFlags)
    Local $sTypeFlags
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FAPPOBJECT) ? "APPOBJECT " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FCANCREATE) ? "CANCREATE " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FLICENSED) ? "LICENSED " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FPREDECLID) ? "PREDECLID " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FHIDDEN) ? "HIDDEN " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FCONTROL) ? "CONTROL " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FDUAL) ? "DUAL " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FNONEXTENSIBLE) ? "NONEXTENSIBLE " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FOLEAUTOMATION) ? "OLEAUTOMATION " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FRESTRICTED) ? "RESTRICTED " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FAGGREGATABLE) ? "AGGREGATABLE " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FREPLACEABLE) ? "REPLACEABLE " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FDISPATCHABLE) ? "DISPATCHABLE " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FREVERSEBIND) ? "REVERSEBIND " : "")
    $sTypeFlags &= (BitAND($iTypeFlags, $TYPEFLAG_FPROXY) ? "PROXY" : "")
    Return $sTypeFlags
EndFunc   ;==>TypeFlagsToString

Func TypeKindToString($iTypeKind)
    If $iTypeKind < 0 Or $iTypeKind > 8 Then Return "ERROR"
    Local $aTypeKind[9] = ["ENUM", "RECORD", "MODULE", "INTERFACE", "DISPATCH", "COCLASS", "ALIAS", "UNION", "MAX"]
    Return $aTypeKind[$iTypeKind]
EndFunc   ;==>TypeKindToString



Output IWebBrowserApp


Type Attributes:
IId = {D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}
Functions = 19
Variables = 0
Interfaces = 1
VTBL Sz = 284
Alignment = Align on Byte 4
Ver = 0.0

hresult Navigate2 (variant*, variant*, variant*, variant*, variant*)
hresult QueryStatusWB (OLECMDID, OLECMDF*)
hresult ExecWB (OLECMDID, OLECMDEXECOPT, variant*, variant*)
hresult ShowBrowserBar (variant*, variant*, variant*)
hresult get_ReadyState (tagREADYSTATE*)
hresult get_Offline (VARIANT_BOOL*)
hresult set_Offline (VARIANT_BOOL)
hresult get_Silent (VARIANT_BOOL*)
hresult set_Silent (VARIANT_BOOL)
hresult get_RegisterAsBrowser (VARIANT_BOOL*)
hresult set_RegisterAsBrowser (VARIANT_BOOL)
hresult get_RegisterAsDropTarget (VARIANT_BOOL*)
hresult set_RegisterAsDropTarget (VARIANT_BOOL)
hresult get_TheaterMode (VARIANT_BOOL*)
hresult set_TheaterMode (VARIANT_BOOL)
hresult get_AddressBar (VARIANT_BOOL*)
hresult set_AddressBar (VARIANT_BOOL)
hresult get_Resizable (VARIANT_BOOL*)
hresult set_Resizable (VARIANT_BOOL)


Output ObjCreate(MediaPlayer.MediaPlayer.1)


Type Attributes:
IId = {20D4F5E0-5475-11D2-9774-0000F80855E6}
Type Kind = DISPATCH
Functions = 192
Variables = 0
Interfaces = 1
VTBL Sz = 28
Alignment = Align on Byte 4
Ver = 0.0

void QueryInterface (GUID*, void**)
ulong AddRef ()
ulong Release ()
void GetTypeInfoCount (UINT*)
void GetTypeInfo (UINT, ulong, void**)
void GetIDsOfNames (GUID*, char**, UINT, ulong, long*)
void Invoke (long, GUID*, ulong, ushort, DISPPARAMS*, variant*, EXCEPINFO*, UINT*)
double get_CurrentPosition ()
void set_CurrentPosition (double)
double get_Duration ()
long get_ImageSourceWidth ()
long get_ImageSourceHeight ()
long get_MarkerCount ()
VARIANT_BOOL get_CanScan ()
VARIANT_BOOL get_CanSeek ()
VARIANT_BOOL get_CanSeekToMarkers ()
long get_CurrentMarker ()
void set_CurrentMarker (long)
bstr get_FileName ()
void set_FileName (bstr)
bstr get_SourceLink ()
date get_CreationDate ()
bstr get_ErrorCorrection ()
long get_Bandwidth ()
long get_SourceProtocol ()
long get_ReceivedPackets ()
long get_RecoveredPackets ()
long get_LostPackets ()
long get_ReceptionQuality ()
long get_BufferingCount ()
VARIANT_BOOL get_IsBroadcast ()
long get_BufferingProgress ()
bstr get_ChannelName ()
bstr get_ChannelDescription ()
bstr get_ChannelURL ()
bstr get_ContactAddress ()
bstr get_ContactPhone ()
bstr get_ContactEmail ()
double get_BufferingTime ()
void set_BufferingTime (double)
VARIANT_BOOL get_AutoStart ()
void set_AutoStart (VARIANT_BOOL)
VARIANT_BOOL get_AutoRewind ()
void set_AutoRewind (VARIANT_BOOL)
double get_Rate ()
void set_Rate (double)
VARIANT_BOOL get_SendKeyboardEvents ()
void set_SendKeyboardEvents (VARIANT_BOOL)
VARIANT_BOOL get_SendMouseClickEvents ()
void set_SendMouseClickEvents (VARIANT_BOOL)
VARIANT_BOOL get_SendMouseMoveEvents ()
void set_SendMouseMoveEvents (VARIANT_BOOL)
long get_PlayCount ()
void set_PlayCount (long)
VARIANT_BOOL get_ClickToPlay ()
void set_ClickToPlay (VARIANT_BOOL)
VARIANT_BOOL get_AllowScan ()
void set_AllowScan (VARIANT_BOOL)
VARIANT_BOOL get_EnableContextMenu ()
void set_EnableContextMenu (VARIANT_BOOL)
long get_CursorType ()
void set_CursorType (long)
long get_CodecCount ()
VARIANT_BOOL get_AllowChangeDisplaySize ()
void set_AllowChangeDisplaySize (VARIANT_BOOL)
VARIANT_BOOL get_IsDurationValid ()
long get_OpenState ()
VARIANT_BOOL get_SendOpenStateChangeEvents ()
void set_SendOpenStateChangeEvents (VARIANT_BOOL)
VARIANT_BOOL get_SendWarningEvents ()
void set_SendWarningEvents (VARIANT_BOOL)
VARIANT_BOOL get_SendErrorEvents ()
void set_SendErrorEvents (VARIANT_BOOL)
MPPlayStateConstants get_PlayState ()
VARIANT_BOOL get_SendPlayStateChangeEvents ()
void set_SendPlayStateChangeEvents (VARIANT_BOOL)
MPDisplaySizeConstants get_DisplaySize ()
void set_DisplaySize (MPDisplaySizeConstants)
VARIANT_BOOL get_InvokeURLs ()
void set_InvokeURLs (VARIANT_BOOL)
bstr get_BaseURL ()
void set_BaseURL (bstr)
bstr get_DefaultFrame ()
void set_DefaultFrame (bstr)
VARIANT_BOOL get_HasError ()
bstr get_ErrorDescription ()
long get_ErrorCode ()
VARIANT_BOOL get_AnimationAtStart ()
void set_AnimationAtStart (VARIANT_BOOL)
VARIANT_BOOL get_TransparentAtStart ()
void set_TransparentAtStart (VARIANT_BOOL)
long get_Volume ()
void set_Volume (long)
long get_Balance ()
void set_Balance (long)
MPReadyStateConstants get_ReadyState ()
double get_SelectionStart ()
void set_SelectionStart (double)
double get_SelectionEnd ()
void set_SelectionEnd (double)
VARIANT_BOOL get_ShowDisplay ()
void set_ShowDisplay (VARIANT_BOOL)
VARIANT_BOOL get_ShowControls ()
void set_ShowControls (VARIANT_BOOL)
VARIANT_BOOL get_ShowPositionControls ()
void set_ShowPositionControls (VARIANT_BOOL)
VARIANT_BOOL get_ShowTracker ()
void set_ShowTracker (VARIANT_BOOL)
VARIANT_BOOL get_EnablePositionControls ()
void set_EnablePositionControls (VARIANT_BOOL)
VARIANT_BOOL get_EnableTracker ()
void set_EnableTracker (VARIANT_BOOL)
VARIANT_BOOL get_Enabled ()
void set_Enabled (VARIANT_BOOL)
OLE_COLOR get_DisplayForeColor ()
void set_DisplayForeColor (OLE_COLOR)
OLE_COLOR get_DisplayBackColor ()
void set_DisplayBackColor (OLE_COLOR)
MPDisplayModeConstants get_DisplayMode ()
void set_DisplayMode (MPDisplayModeConstants)
VARIANT_BOOL get_VideoBorder3D ()
void set_VideoBorder3D (VARIANT_BOOL)
long get_VideoBorderWidth ()
void set_VideoBorderWidth (long)
OLE_COLOR get_VideoBorderColor ()
void set_VideoBorderColor (OLE_COLOR)
VARIANT_BOOL get_ShowGotoBar ()
void set_ShowGotoBar (VARIANT_BOOL)
VARIANT_BOOL get_ShowStatusBar ()
void set_ShowStatusBar (VARIANT_BOOL)
VARIANT_BOOL get_ShowCaptioning ()
void set_ShowCaptioning (VARIANT_BOOL)
VARIANT_BOOL get_ShowAudioControls ()
void set_ShowAudioControls (VARIANT_BOOL)
bstr get_CaptioningID ()
void set_CaptioningID (bstr)
VARIANT_BOOL get_Mute ()
void set_Mute (VARIANT_BOOL)
VARIANT_BOOL get_CanPreview ()
VARIANT_BOOL get_PreviewMode ()
void set_PreviewMode (VARIANT_BOOL)
VARIANT_BOOL get_HasMultipleItems ()
long get_Language ()
void set_Language (long)
long get_AudioStream ()
void set_AudioStream (long)
bstr get_SAMIStyle ()
void set_SAMIStyle (bstr)
bstr get_SAMILang ()
void set_SAMILang (bstr)
bstr get_SAMIFileName ()
void set_SAMIFileName (bstr)
long get_StreamCount ()
bstr get_ClientId ()
long get_ConnectionSpeed ()
VARIANT_BOOL get_AutoSize ()
void set_AutoSize (VARIANT_BOOL)
VARIANT_BOOL get_EnableFullScreenControls ()
void set_EnableFullScreenControls (VARIANT_BOOL)
IDispatch* get_ActiveMovie ()
IDispatch* get_NSPlay ()
VARIANT_BOOL get_WindowlessVideo ()
void set_WindowlessVideo (VARIANT_BOOL)
void set_Play ()
void set_Stop ()
void set_Pause ()
double set_GetMarkerTime (long)
bstr set_GetMarkerName (long)
void set_AboutBox ()
VARIANT_BOOL set_GetCodecInstalled (long)
bstr set_GetCodecDescription (long)
bstr set_GetCodecURL (long)
bstr set_GetMoreInfoURL (MPMoreInfoType)
bstr set_GetMediaInfoString (MPMediaInfoType)
void set_Cancel ()
void set_Open (bstr)
VARIANT_BOOL set_IsSoundCardEnabled ()
void set_Next ()
void set_Previous ()
void set_StreamSelect (long)
void set_FastForward ()
void set_FastReverse ()
bstr set_GetStreamName (long)
long set_GetStreamGroup (long)
VARIANT_BOOL set_GetStreamSelected (long)
IMediaPlayerDvd* get_DVD ()
bstr get_GetMediaParameter (long, bstr)
bstr get_GetMediaParameterName (long, long)
long get_EntryCount ()
long get_GetCurrentEntry ()
void get_SetCurrentEntry (long)
void get_ShowDialog (MPShowDialogConstants)


Edited by Bilgus

Share this post

Link to post
Share on other sites

maybe this:




Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."


Signature last update: 2018-10-31

Share this post

Link to post
Share on other sites

@mLipok The First link is in a similar vein it looks to be parsing the TLB, Whereas this is using the interfaces directly

Not sure what the second link is supposed to point to

Thanks, It's nice to see other examples..

Share this post

Link to post
Share on other sites

Not sure why I hadn't tried this before but I guess you can use ObjCreateInterface with an existing interface

Global $oObject = ObjCreate("MediaPlayer.MediaPlayer.1")
        ;...IDispatch isn't exposed ATM
        If ObjName($oObject, 1) <> "InterfaceDispatch" Then
            $oObject = ObjCreateInterface($oObject, $sIID_IDispatch, $dtag_IDispatch) ;Try To get IDispatch
        ;...IDispatch is exposed

Added to example in first post

Share this post

Link to post
Share on other sites


Very nice ! It will be useful for the .NET CLR UDF as well

I see you reused some the CLR.au3 code

Global Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
Global Const $dtag_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.




Edited by ptrex

Share this post

Link to post
Share on other sites

@ptrex Thanks for the hint on your .Net Clr Udf those interface defines, safearray.au3 and variant.au3 would have saved me quite a bit of coding between this and the FwPolicy2 Udf I posted

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

  • Similar Content

    • By Bilgus
      Trying to figure out how to do CallByName on AutoIt COM objects due to the lack of being able to set properties within an Execute() statement
      Several Ideas were Tried https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/
      I think this is the best; Patching the vtable of IDispatch so we can intercept a Fake function call ($obj.Au3_CallByName)
      use it like this
      Local $oDictionary = ObjCreate("Scripting.Dictionary") ; EXAMPLE Au3_CallByname_Init() ; (you can optionally provide a classname here but we patch the main Idispatch interface so really no need) $Au3_CallByName = "Add" ; Method we want to call $oDictionary.Au3_CallByName("Test", "Value") Au3_CallByname_Init(False) ; (Not Strictly Needed unhooked on exit) NOTE:  Au3_CallByname_Init() doesn't have to be called at the top of the script, just call it before you need to call by name...
      Code + Example
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Au3CallByName, Bilgus Global $Au3_CallByName = 0 Local $hKernel32 = DllOpen("Kernel32.dll") OnAutoItExitRegister(__CallByNameCleanup) Func __CallByNameCleanup() Au3_CallByName_Init(False) ;Unload DllClose($hKernel32) EndFunc ;==>__CallByNameCleanup ; Takes a pointer to the v-table in a class and replaces specified member Id in it to a new one. Func __HookVTableEntry($pVtable, $iVtableOffset, $pHook, ByRef $pOldRet) ;;https://www.autoitscript.com/forum/topic/107678-hooking-into-the-idispatch-interface/ Local Const $PAGE_READWRITE = 0x04 Local $tpVtable = DllStructCreate("ptr", $pVtable) Local $szPtr = DllStructGetSize($tpVtable) Local $pFirstEntry, $pEntry, $tEntry, $aCall, $flOldProtect, $bStatus ; Dereference the vtable pointer $pFirstEntry = DllStructGetData($tpVtable, 1) $pEntry = $pFirstEntry + ($iVtableOffset * $szPtr) ; Make the memory free for all. Yay! $aCall = DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $PAGE_READWRITE, "dword*", 0) If @error Or Not $aCall[0] Then ConsoleWriteError("Error: Failed To hook vTable" & @CRLF) Return False EndIf $flOldProtect = $aCall[4] $tEntry = DllStructCreate("ptr", $pEntry) $pOldRet = DllStructGetData($tEntry, 1) If $pOldRet <> $pHook Then DllStructSetData($tEntry, 1, $pHook) $bStatus = True Else ;Already Hooked ConsoleWriteError("Error: vTable is already hooked" & @CRLF) $bStatus = False EndIf ;put the memory protect back how we found it DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $flOldProtect, "dword*", 0) Return $bStatus EndFunc ;==>__HookVTableEntry ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) Local Const $CSTR_EQUAL = 0x02 Local Const $LOCALE_SYSTEM_DEFAULT = 0x800 Local Const $DISP_E_UNKNOWNNAME = 0x80020006 Local Static $pGIFN = __Pointer_GetIDsFromNames() Local Static $tpMember = DllStructCreate("ptr") If $Au3_CallByName Then Local $hRes, $aCall, $tMember ;autoit only asks for one member $aCall = DllCall($hKernel32, 'int', 'CompareStringW', 'dword', $LOCALE_SYSTEM_DEFAULT, 'dword', 0, 'wstr', "Au3_CallByName", 'int', -1, _ 'struct*', DllStructGetData(DllStructCreate("ptr[" & $cNames & "]", $rgszNames), 1, 1), 'int', -1) If Not @error And $aCall[0] = $CSTR_EQUAL Then ;ConsoleWrite("CallByName: " & $Au3_CallByName & @CRLF) $tMember = DllStructCreate("wchar[" & StringLen($Au3_CallByName) + 1 & "]") DllStructSetData($tMember, 1, $Au3_CallByName) DllStructSetData($tpMember, 1, DllStructGetPtr($tMember)) $rgszNames = $tpMember $Au3_CallByName = 0 EndIf EndIf ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWrite("Error: GetIDsFromNames: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf Return $hRes[0] EndFunc ;==>__IDispatch_GetIDsFromNames Func __Pointer_GetIDsFromNames($ptr = 0) Local Static $pOldGIFN = $ptr If $ptr <> 0 Then $pOldGIFN = $ptr Return $pOldGIFN EndFunc ;==>__Pointer_GetIDsFromNames Func Au3_CallByName_Init($bHook = True, $classname = "shell.application") Local Const $iOffset_GetIDsFromNames = 5 Local Static $IDispatch_GetIDsFromNames_Callback = 0 Local $oObject, $pObject, $pHook, $pOldGIFN If $bHook Then If $IDispatch_GetIDsFromNames_Callback = 0 Then $IDispatch_GetIDsFromNames_Callback = DllCallbackRegister("__IDispatch_GetIDsFromNames", "LRESULT", "ptr;ptr;ptr;dword;dword;ptr") EndIf $pHook = DllCallbackGetPtr($IDispatch_GetIDsFromNames_Callback) Else $pHook = __Pointer_GetIDsFromNames() If $pHook <= 0 Then Return ;Already Unloaded EndIf $oObject = ObjCreate($classname) $pObject = DllStructSetData(DllStructCreate("ptr"), 1, $oObject) If __HookVTableEntry($pObject, $iOffset_GetIDsFromNames, $pHook, $pOldGIFN) Then __Pointer_GetIDsFromNames($pOldGIFN) ;Save the original pointer to GetIDsFromNames If Not $bHook Then DllCallbackFree($IDispatch_GetIDsFromNames_Callback) $IDispatch_GetIDsFromNames_Callback = 0 EndIf Else ;Error EndIf $oObject = 0 EndFunc ;==>Au3_CallByName_Init ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;TESTS; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Au3_CallByName_Init() #include <ie.au3> Global $oRegistrationInfo = _IECreate() Global $aRegistrationInfo[] = ['Left=10', 'Top= 10', 'Width=450', 'Height=600'] Global $oObject = $oRegistrationInfo Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $oDictionary2 = ObjCreate("Scripting.Dictionary") ;Au3_CallByName_Init($oObject) __TS_TaskPropertiesSet($oObject, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit $oRegistrationInfo = 0 $oObject = 0 Sleep(1000) For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary.Au3_CallByName("test1:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload Au3_CallByName_Init() Local $aRegistrationInfo[] = ['Left=1000', 'Width=450'] ConsoleWrite(@CRLF & "NEW IE" & @CRLF & @CRLF) $oRegistrationInfo = _IECreate() __TS_TaskPropertiesSet($oRegistrationInfo, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary2.Au3_CallByName("test2:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary2.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary2.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload (Not Strictly Needed, Done on Script Close) Func __TS_TaskPropertiesSet(ByRef $oObject, $aProperties) Local $aTemp If IsArray($aProperties) Then For $i = 0 To UBound($aProperties) - 1 $aTemp = StringSplit($aProperties[$i], "=", 2) ; 2 -> $STR_NOCOUNT) If @error Then ContinueLoop ConsoleWrite("Command: $oObject." & $aTemp[0] & " = " & $aTemp[1] & @CRLF) $Au3_CallByName = $aTemp[0] $oObject.Au3_CallByName = $aTemp[1] ConsoleWrite("Result : " & Hex(@error) & @CRLF) ; If @error Then Return SetError(1, @error, 0) Next EndIf EndFunc ;==>__TS_TaskPropertiesSet  
    • By mLipok
      Today, in the end as well, worked out using the Acrobat Reader ActiveX COM Object "AcroPDF.PDF.1"
      #include-once #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <MenuConstants.au3> #include <WinAPI.au3> ;~ Thanks to BrewManNH ;~ http://www.autoitscript.com/forum/topic/134878-guiregistermsg-replacement-for-guictrlsetonevent-and-guigetmsg/ ;~ Thanks to mikell ;~ http://www.autoitscript.com/forum/topic/161985-how-to-close-gui-with-guiregistermsg/ ; Install a custom error handler Global $oMyError = ObjEvent("AutoIt.Error", "_ComErrFunc") Global $__hExampleGUI Global $__idOPEN Global $_fExit Global $__hACROBAT_GUI = '' Global $__idACROBAT_GUI_CTRL_AX = '' Global $__oACROBAT_READER = '' #include <GUIConstantsEx.au3> ;~ GUIRegisterMsg($WM_ERASEBKGND, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_PAINT, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_ACTIVATE, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_CAPTURECHANGED, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_DEVICECHANGE, "_WM_EXTRACTOR") GUIRegisterMsg($WM_EXITSIZEMOVE, "_WM_EXTRACTOR") GUIRegisterMsg($WM_COMMAND, "_WM_EXTRACTOR") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_EXTRACTOR") GUIRegisterMsg($WM_HSCROLL, "_WM_EXTRACTOR") _ExampleProgram_Gui() While 1 Sleep(10) If $_fExit Then _ACROBAT_GUI_DELETE() DeleteGui() Exit EndIf WEnd Func DeleteGui() GUIDelete($__hExampleGUI) EndFunc ;==>DeleteGui Func _ExampleProgram_Gui() ; Create a GUI with various controls. $__hExampleGUI = GUICreate("Example") $__idOPEN = GUICtrlCreateButton("&Open", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $__hExampleGUI) EndFunc ;==>_ExampleProgram_Gui #Region ACROBAT FUNCTION Func _AcrobatInit() $__oACROBAT_READER = ObjCreate("AcroPDF.PDF.1"); Return $__oACROBAT_READER.GetVersions EndFunc ;==>_AcrobatInit Func _Acrobat_Events(ByRef $aMSG) If $aMSG[1] = $__hACROBAT_GUI Then Switch $aMSG[0] Case $GUI_EVENT_CLOSE _ACROBAT_GUI_DELETE() EndSwitch EndIf EndFunc ;==>_Acrobat_Events Func _ACROBAT_Destroy() $__oACROBAT_READER = "" ;~ MsgBox(1,'test','destroyed') EndFunc ;==>_ACROBAT_Destroy Func _AcrobatShow($sFile, $sTitle = "PDF ", $iLeft = 50, $iTop = 0, $iWidth = 1000, $iHeight = 700) If FileExists($sFile) Then _AcrobatInit() ; Set option $__oACROBAT_READER.src = $sFile $__oACROBAT_READER.SetLayoutMode(4) $__oACROBAT_READER.SetPageMode(1) $__oACROBAT_READER.SetShowToolbar(0) $__oACROBAT_READER.SetView(1) ; Create GUI $__hACROBAT_GUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX)) $__idACROBAT_GUI_CTRL_AX = GUICtrlCreateObj($__oACROBAT_READER, 5, 5, $iWidth - 20, $iHeight - 10) GUICtrlSetStyle($__idACROBAT_GUI_CTRL_AX, $WS_VISIBLE) GUISetState() EndIf EndFunc ;==>_AcrobatShow Func _ACROBAT_Refresh() If IsObj($__oACROBAT_READER) Then Local $hPreviouslyGui = GUISwitch($__hACROBAT_GUI) GUISetState(@SW_LOCK) Local $iGUI_PDFWidth = WinGetPos($__hACROBAT_GUI)[2] - 20 Local $iGUI_PDFHeight = WinGetPos($__hACROBAT_GUI)[3] - 40 Local $sFile = $__oACROBAT_READER.src ; this below line do not works with Acro Reader ; Local $iCurrentPage = $__oACROBAT_READER.GetNumber Local $iCurrentPage = 0 _ACROBAT_Destroy() GUICtrlDelete($__idACROBAT_GUI_CTRL_AX) _AcrobatInit() $__idACROBAT_GUI_CTRL_AX = GUICtrlCreateObj($__oACROBAT_READER, 5, 5, $iGUI_PDFWidth, $iGUI_PDFHeight) $__oACROBAT_READER.src = $sFile ;~ $__oACROBAT_READER.SetCurrentPage($iCurrentPage) GUISetState(@SW_UNLOCK) GUISwitch($hPreviouslyGui) EndIf EndFunc ;==>_ACROBAT_Refresh Func _ACROBAT_GUI_DELETE() _ACROBAT_Destroy() if IsHWnd($__hACROBAT_GUI) then GUIDelete($__hACROBAT_GUI) EndFunc ;==>_ACROBAT_GUI_DELETE #EndRegion ACROBAT FUNCTION #Region MSG and ERROR HANDLER Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam) ;~ ConsoleWrite('! $hWnd = ' & $hWnd & ' $iMsg = ' & $iMsg & '('&HEX($iMsg)&')'& ' $wParam = ' & $wParam & ' $lParam = ' & $lParam & @CRLF) If $hWnd = ControlGetHandle($__hACROBAT_GUI, '', $__idACROBAT_GUI_CTRL_AX) Then ConsoleWrite('! -------------- $hWnd = ' & $hWnd & ' $iMsg = ' & $iMsg & '(' & Hex($iMsg) & ')' & ' $wParam = ' & $wParam & ' $lParam = ' & $lParam & @CRLF) EndIf If $hWnd = $__hACROBAT_GUI Then Switch $iMsg Case $WM_COMMAND #cs Case $WM_ACTIVATE Local $test = BitAND($wParam, 0x00000004) if $test <> 0 then MsgBox(1,'$WM_ACTIVATE','test') _ACROBAT_Refresh() EndIf Case $WM_ERASEBKGND WinGetHandle("[ACTIVE]") if $__hACROBAT_GUI <> _WinAPI_GetWindow ( $__hACROBAT_GUI, $GW_HWNDPREV ) then ConsoleWrite('! Case $WM_ERASEBKGND' & @CRLF) _ACROBAT_Refresh() _WinAPI_RedrawWindow($__hACROBAT_GUI,0,0,$RDW_NOERASE) EndIf Case $WM_PAINT _WinAPI_RedrawWindow($__hACROBAT_GUI,0,0,$RDW_NOERASE) Case $WM_CAPTURECHANGED _ACROBAT_Refresh() Case $WM_DEVICECHANGE _ACROBAT_Refresh() #ce Case $WM_EXITSIZEMOVE _ACROBAT_Refresh() Case $WM_SYSCOMMAND ;~ Local $test = BitAND($wParam, 0xFFF0) Local $test = BitAND($wParam, 0x0000FFFF) Switch $test Case $SC_CLOSE _ACROBAT_GUI_DELETE() Case $SC_CONTEXTHELP Case $SC_DEFAULT Case $SC_HOTKEY Case $SC_HSCROLL Case $SC_KEYMENU Case $SC_MAXIMIZE _ACROBAT_Refresh() Case $SC_MINIMIZE Case $SC_MONITORPOWER Case $SC_MOUSEMENU Case $SC_MOVE ;~ _ACROBAT_Refresh() Case $SC_NEXTWINDOW ;~ _ACROBAT_Refresh() Case $SC_PREVWINDOW ;~ _ACROBAT_Refresh() Case $SC_RESTORE _ACROBAT_Refresh() Case $SC_SCREENSAVE Case $SC_SIZE Case $SC_TASKLIST Case $SC_VSCROLL EndSwitch EndSwitch EndIf If $hWnd = $__hExampleGUI Then Switch $iMsg Case $WM_COMMAND Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam Switch $nID Case $__idOPEN if not IsObj($__oACROBAT_READER) then _AcrobatShow(FileOpenDialog("Choose PDF", "C:\Temp", "PDF Files(*.pdf)", 3)) ; put your own start folder here) EndIf EndSwitch Case $WM_SYSCOMMAND Local $test = BitAND($wParam, 0xFFF0) Switch $test Case $SC_CLOSE $_fExit = True Case $SC_CONTEXTHELP Case $SC_DEFAULT Case $SC_HOTKEY Case $SC_HSCROLL Case $SC_KEYMENU Case $SC_MAXIMIZE Case $SC_MINIMIZE Case $SC_MONITORPOWER Case $SC_MOUSEMENU Case $SC_MOVE Case $SC_NEXTWINDOW Case $SC_PREVWINDOW Case $SC_RESTORE Case $SC_SCREENSAVE Case $SC_SIZE Case $SC_TASKLIST Case $SC_VSCROLL EndSwitch EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_EXTRACTOR Func _ComErrFunc() Local $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "AutoItCOM Test", _ "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) EndFunc ;==>_ComErrFunc #EndRegion MSG and ERROR HANDLER Any comments are welcome.
    • By jantograaf
      Hi all,
      I'm trying to write a script that connects with a VBA/COM API to get the status of a connected phone. I've been looking up and down this forum for tips or other user's experiences, but I can't seem to find anything (even remotely) similar. It shouldn't be so hard to do, however.
      Software I'm trying to connect to
      I'm trying to integrate CallCenter by using their API, which is documented over here : JustRemotePhone API Reference
      Things I've tried
      I've tried using ObjCreate but I don't get any result, it always returns the same (negative) error.
      #Version 1 tried ObjCreate("JustRemotePhone.RemotePhoneService") #Version 2 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService") #Version 3 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService.Application") None of the three versions I tried seem to deliver any result other than a negative error value which basically says that the given class is not valid.
      I am starting to get the hang of AutoIt by now, but unmanaged programming languages and object-oriented stuff is still quite a grey zone for me. If anyone could help me 'talk' to this application, I'd be immensely grateful!
      Thanks in advance and kind regards from Belgium!
    • By Rhidlor
      So I'm trying to do some as400 automation and hit a wall when trying to get a COM object. The code on line 8 is failing, the as400.ws file opens with PCSWS.exe so I tried using that as the file path too but that didn't work either. Any and all help is greatly appreciated! 
      $file = "C:\Users\Rhidlor\Desktop\as400.ws" If Not FileExists($file) Then MsgBox(0, "Error", "Error finding file") Exit EndIf $object = ObjGet($file) If @error Then MsgBox(0, "Error", "Error getting object") Exit EndIf $object.SendKeys("05")  
    • By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version :
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      Test Script:
  • Create New...