[Erlang Systems]

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 integer
string VT_STR, unicode string
atom no type, however the two atomstrue and false are converted to VT_BOOL, the COM Boolean type
float VT_R8, 64-bits floating point
Erlang 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}.

The comet application consists of two parts: the gen_server module erl_com, that implements the Erlang API for comet, and the port (driver or program) erl_com_drv, that communicates with COM objects. The port is never called directly, only through API functions in erl_com.

There is also a module com_gen that can generate Erlang APIs for COM object, by querying their type libraries.

2.2 How comet works

TBD

2.3 Using objects and interfaces

TBD

2.4 Using the dispatch interface

The dispatch or IDispatch interface is a way for scripts to call functions. 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_put_ref(Interface, Method, Parameterlist, Value) Sets a property value REF. See COM documentation for more info.
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.
Functions for dispatch interfaces

The parameter Method above, is either a string or a member ID.

Examples of using this:

erl_com:invoke(Obj, "Navigate", ["www.erlang.org"])

erl_com:property_put(Obj, "Visible", true)

Here we assume that Obj is an IWebBrowser interface for an Internet Explorer program.

Calling methods this way is OK for testing things in an Erlang shell, but it's not very practical and does not make for readable code. A much simpler way of using COM objects is to generate them first and then call them.

2.5 Other functions

TBD

2.6 Generating stub modules

The com_gen erlang module, has functions for generating stub modules for COM interfaces and classes.

In COM, type information is compiled from an IDL-file, and stored in a "type library". This is a collection of type information, that is readable (via COM) from erlang.

TBD


Copyright © 1991-2001 Ericsson Utvecklings AB