Jump to content

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


Bilgus
 Share

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

ITypeInfoCOM.au3

Spoiler
;Bilgus 2018
;ITypeInfoCOM
#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 ===

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

;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 Enum Step *2 $TYPEFLAG_FAPPOBJECT = 0x1, $TYPEFLAG_FCANCREATE, $TYPEFLAG_FLICENSED, _
        $TYPEFLAG_FPREDECLID, $TYPEFLAG_FHIDDEN, $TYPEFLAG_FCONTROL, $TYPEFLAG_FDUAL, _
        $TYPEFLAG_FNONEXTENSIBLE, $TYPEFLAG_FOLEAUTOMATION, $TYPEFLAG_FRESTRICTED, _
        $TYPEFLAG_FAGGREGATABLE, $TYPEFLAG_FREPLACEABLE, $TYPEFLAG_FDISPATCHABLE, _
        $TYPEFLAG_FREVERSEBIND, $TYPEFLAG_FPROXY

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 $tagELEMDESC = "STRUCT;" & $tagTYPEDESC & $tagPARAMDESC & "ENDSTRUCT;" ;&UNIONS
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 & _
        "ENDSTRUCT;"

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;" & _
        "ENDSTRUCT;"

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
    EndIf

    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_"
                Else
                    $sPrefix = ""
                EndIf

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

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

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

            $oITypeInfo.ReleaseFuncDesc($pFuncDesc) ;Important! Release FUNCDESC
        Else
            ConsoleWriteError("Error Retrieving Function Description: " & Hex($iResult) & @CRLF)
        EndIf
    Next
    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
    EndIf

    If (Not @error) And (Not $iResult) And $aWstrName[0] Then
        $sFunctionName = WstrExtract_pp($aWstrName) ;Function Name **WSTR
        __SysFreeString($aWstrName[0]) ; Free the BSTR
    Else
        $iError = 1
    EndIf
    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)
    Else
        $iError = 1
    EndIf

    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
            ExitLoop
        EndIf

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

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

        $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
            ExitLoop
        EndIf
        ExitLoop
    WEnd
    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
    Next
    Return $sParameterTypes
EndFunc   ;==>Get_ParameterList

Func StringifyCustomType($pTypeDesc_hRef, ByRef $oITypeInfo)
    ;Sean Baxter, COM Automation: Type Information (Part II)
    ;http://yanaware.com/com4me/typeinfo2.php-author=Sean%20BAXTER&mail=spec@ript.net&url=http---ript.net-~spec-&idTute=13.htm
    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
        EndIf
        ExitLoop
    WEnd

    Return $sString

EndFunc   ;==>StringifyCustomType

Func StringifyTypeDesc($pElemDesc, ByRef $oITypeInfo)
    ;Sean Baxter, COM Automation: Type Information (Part II)
    ;http://yanaware.com/com4me/typeinfo2.php-author=Sean%20BAXTER&mail=spec@ript.net&url=http---ript.net-~spec-&idTute=13.htm
    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)
    EndIf

    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!"
    EndSwitch
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]
    EndIf

    If (Not IsPtr($pPointer)) Then
        $iError = 1
        $pPointer = 0
    EndIf
    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")
        EndIf
    EndIf
    Return $sString
EndFunc   ;==>WstrExtract_pp

 

ITypeInfoTest.au3

Spoiler
;TypeInfo
#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)

Exit

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

Func PrintArray($aArr)
    $sRet = ""
    If IsArray($aArr) Then
        For $i = 0 To UBound($aArr) - 1
            $sRet &= $aArr[$i] & @CRLF
        Next
    EndIf
    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

Spoiler

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

Functions:
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)

Spoiler

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

Functions:
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
Link to comment
Share on other sites

maybe this:

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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 * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

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 * SciTE - Lexer for console pane

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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
        EndIf
        ;...IDispatch is exposed

Added to example in first post

Link to comment
Share on other sites

@Bilgus

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.

 

Rgds,

ptrex

Edited by ptrex
Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...