2 Comet
2.1 Basic COM from Erlang
In COM, there are interfaces. An interface is a handle to an object. Physically it consists of a pointer to an object with a method table.
Interfaces in COM are represented as a tuple in Erlang. This tuple should be considered oblique data.
There is a standard set of types in COM. These types can be converted to and from Erlang by the port program. (It is actually converted from the Erlang binary format.) Table 1 shows the types in Erlang and their corresponding COM type.
integer
VT_I4
, 32-bits integerstring
VT_STR
, unicode stringatom
no type, however the two atoms true
andfalse
are converted toVT_BOOL
, the COM Boolean typefloat
VT_R8
, 64-bits floating pointErlang types and their corresponding COM type However, there are fewer types in Erlang than in COM, so some types overlap. When calling a COM function, the parameters types must match exactly, since COM is strongly typed. Comet uses a special notation for the conversion of Erlang types to COM types, a tuple with an atom followed by the value, e.g.
{vt_i2, 12}
2.2 Using the IDispatch interface
The
IDispatch
interface is a way for scripts to call a COM function. It is used by Visual Basic, JScript and other scripting language. It is sometimes referred to as the late-binding call interface.This way to call COM objects shows off its VB heritage. An interface has methods and properties. A property is really two methods: put property and get property.
In the
erl_com
server, there are three functions for calling an IDispatch-interface.
invoke(Interface, Method, Parameterlist)
Invokes a normal COM method. A list of out-parameters are returned, or, if there is a retval-parameter, it is returned. property_put(Interface, Method, Parameterlist, Value)
Calls a COM method with the propput
-attribute. An extra argument, after the Parameterlist, contains the property value to set. (Which really is just a parameter to the function.) If the property does not have parameters, the parameterlist might be omitted, but a value must always be provided.property_get(Interface, Method, Parameterlist)
Calls a COM method with the propget
-attribute. The value of the property is returned. If the property does not have parameters, the parameterlist might be omitted.calling an IDispatch interface