ComObjType()

Auto Hotkey

ComObjType

Retrieves type information from a COM object.

OutputVar := ComObjType(ComObject , Value)
Function Example: IID := ComObjType(ComObject,"Name")

Parameters

OutputVar

The name of the variable in which to store the result depending on Parameter, see Value.

ComObject

A wrapper object containing a COM object or typed value.

Value (optional)

The result will differ depending on this parameter:

  • VarType - Omitt the Value parameter to retrieve the type of value.
  • Name - Pass "Name" in Value parameter to retrieve the interface type name.
  • IID - Pass "IID" in Value parameter to retrieve a globally unique identifier (GUID) representing the interface type.
  • .

    Variant Type Constants

    VT_EMPTY     :=      0  ; No value
    VT_NULL      :=      1  ; SQL-style Null
    VT_I2        :=      2  ; 16-bit signed int
    VT_I4        :=      3  ; 32-bit signed int
    VT_R4        :=      4  ; 32-bit floating-point number
    VT_R8        :=      5  ; 64-bit floating-point number
    VT_CY        :=      6  ; Currency
    VT_DATE      :=      7  ; Date
    VT_BSTR      :=      8  ; COM string (Unicode string with length prefix)
    VT_DISPATCH  :=      9  ; COM object
    VT_ERROR     :=    0xA  ; Error code (32-bit integer)
    VT_BOOL      :=    0xB  ; Boolean True (-1) or False (0)
    VT_VARIANT   :=    0xC  ; VARIANT (must be combined with VT_ARRAY or VT_BYREF)
    VT_UNKNOWN   :=    0xD  ; IUnknown interface pointer
    VT_DECIMAL   :=    0xE  ; (not supported)
    VT_I1        :=   0x10  ; 8-bit signed int
    VT_UI1       :=   0x11  ; 8-bit unsigned int
    VT_UI2       :=   0x12  ; 16-bit unsigned int
    VT_UI4       :=   0x13  ; 32-bit unsigned int
    VT_I8        :=   0x14  ; 64-bit signed int
    VT_UI8       :=   0x15  ; 64-bit unsigned int
    VT_INT       :=   0x16  ; Signed machine int
    VT_UINT      :=   0x17  ; Unsigned machine int
    VT_RECORD    :=   0x24  ; User-defined type -- NOT SUPPORTED
    VT_ARRAY     := 0x2000  ; SAFEARRAY
    VT_BYREF     := 0x4000  ; Pointer to another type of value
    /*
     VT_ARRAY and VT_BYREF are combined with another value (using bitwise OR)
     to specify the exact type. For instance, 0x2003 identifies a SAFEARRAY
     of 32-bit signed integers and 0x400C identifies a pointer to a VARIANT.
    */
    

    General Remarks

    In most common cases, return values from methods or properties of COM objects are converted to an appropriate data type supported by AutoHotkey. Types which aren't specifically handled are coerced to strings via VariantChangeType; if this fails or if the variant type contains the VT_ARRAY or VT_BYREF flag, an object containing both the value and its type is returned instead.

    For any variable x, if ComObjType(x) returns an integer, x contains a COM object wrapper.

    Related

    ComObjValue, ComObject, ComObjCreate, ComObjGet, ComObjActive

    Examples

    d := ComObjCreate("Scripting.Dictionary")
    VarType := ComObjType(d)          ; Always 9 for script-callable objects.
    Name    := ComObjType(d, "Name")  ; Only valid for script-callable objects.
    IID     := ComObjType(d, "IID")   ; As above.
    MsgBox Variant type:`t%VarType%`nType name:`t%Name%`nInterface ID:`t%IID%