ImportTypeLib Documentation

Usage Information - Interfaces

Interfaces are wrapped by ImportTypeLib. They are used to call methods and get or set properties.

Creating an instance

Creating and instance of an interface is actually the process of enwrapping a class instance.
instance := ITL_InterfaceWrapper.__New(ptr)
This form is not directly used by a script, Instead, the new operator can be used:
lib := ImportTypeLib("C:\Path\To\MyLib.tlb")
ptr := new lib.MyClass() ; create a class instance
instance := new lib.IMyInterface(ptr) ; enwrap the pointer with an interface

Parameter

ptr The pointer to an instance of a class implementing the interface. It is not needed to query the pointer for the interface IID, as this is done internally.

Returns

The returned instance is an object which can be used to call methods and get/set properties as described on this page.

Throws

If the given pointer is invalid or if querying that pointer for the interface fails, an exception is thrown.

Calling a method

Calling an interface method is as intuitive and natural as with native support.
retVal := instance.MethodName([Param1, Param2, Param3, ...])

Parameter

MethodName The name of the method as in the interface definition. This is case-insensitive.
Param1, Param2, Param3, ... The parameters as required by the method being called. Right now, it might be necessary for some parameters to be explicitly typed:
VT_UNKNOWN := 0xD
instance.MyMethod(ComObjParameter(VT_UNKNOWN, ptr))

Returns

The return value is the return value of the method, or to be exact, the value of the parameter being marked with the [retval] attribute in the type library.

Throws

An exception is thrown if the method does not exist or can't be called or if calling the method returns a failure code.

Remarks

Unlike with AutoHotkey builtin COM support, the syntax matters: for example, a method can not be called like so:
instance.Method ; incorrect: the brackets () are required. In this way, a property would be retrieved.
instance.Method() ; correct

Retrieving or setting properties

Properties in an interfaces can be retrieved and, if the interface allows it, set in an easy natural way as well.
value := instance.Property ; retrieve a property value
instance.Property := value ; change the value of a property

Parameter

Property The name of the property as in the interface definition. This is case-insensitive.
value Receives the value of a property when retrieving a property or holds the new value the property is set to. As with calling methods, setting a property might require the value to be explicitly typed.

Returns

Retrieving a property of course returns the value, setting a property returns the value given. This allows "chaining" such as in this example:
copy := instance.Property := value ; "copy" holds now the same value as "value"

Throws

An exception may for example occur if the property does not exist, is read-only (and an attempt is made to set it) or if the value for a set-operation is not properly typed.