Retrieves type information from a COM object.
VarType := ComObjType(ComObject) IName := ComObjType(ComObject, "Name") IID := ComObjType(ComObject, "IID") CName := ComObjType(ComObject, "Class") CLSID := ComObjType(ComObject, "CLSID")
A wrapper object containing a COM object or typed value.
The second parameter is a string indicating the type information to retrieve.
The return value depends on the value of Param2:
Param2 | Return Value |
---|---|
Omitted | An integer variant type code indicating the type of value contained by the COM wrapper object. |
"Name" | The name of the object's default interface. |
"IID" | The globally unique identifier (GUID) of the object's default interface. |
"Class" | The object's class name. Note that this is not the same as a Prog ID (a Prog ID is a name used to identify the class in the system registry, or for ComObjCreate). |
"CLSID" | The globally unique identifier (GUID) of the object's class. Classes are often registered by CLSID under the HKCR\CLSID registry key. |
An empty string is returned if either parameter is invalid or if the requested type information could not be retrieved.
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. */
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.
If Param2 is "Name"
or "IID"
, type information is retrieved via the IDispatch::GetTypeInfo interface method. ComObject's variant type must be VT_DISPATCH.
If Param2 is "Class"
or "CLSID"
, type information is retrieved via the IProvideClassInfo::GetClassInfo interface method. ComObject's variant type must be VT_DISPATCH or VT_UNKNOWN, and the object must implement the IProvideClassInfo interface (some objects do not).
ComObjValue, ComObject, ComObjCreate, ComObjGet, ComObjActive
d := ComObjCreate("Scripting.Dictionary") MsgBox " (Q Variant type:`t" ComObjType(d) " Interface name:`t" ComObjType(d, "Name") " Interface ID:`t" ComObjType(d, "IID") " Class name:`t" ComObjType(d, "Class") " Class ID (CLSID):`t" ComObjType(d, "CLSID") " )"