# ComObjType() [v1.0.91+]

Retrieves type information from a COM object.

    VarType := ComObjType(ComObject)
    Name    := ComObjType(ComObject, "Name")
    IID     := ComObjType(ComObject, "IID")

### Parameters

ComObject | A wrapper object containing a COM object or typed value.
VarType | An integer indicating the type of value. See below.
Name | An interface type name.
IID | A globally unique identifier (GUID) representing the interface type.

### Return Value

If the second parameter is omitted, the variant type of the value contained by the wrapper object is returned.

If the second parameter is "Name" or "IID" and the wrapper object contains a COM object (variant type VT_DISPATCH), the COM object's type name or the identifier of its primary interface is returned.

In the parameters are invalid or an error occurs, an empty string is returned.

### 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
    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, 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%