Platform SDK: Exchange 2000 Server

Navigating CDO Interfaces with Visual Basic

[This is preliminary documentation and subject to change.]

Microsoft® Visual Basic® provides a mechanism for navigating interfaces on objects using the Set keyword. When a variable has been dimensioned to a type exported by a referenced type library, Visual Basic will automatically call IUnknown::QueryInterface when the variable is set:

Dim iMsg as CDO.IMessage
Set iMsg = New CDO.Message ' (QueryInterface)

Dim iDsrc as CDO.IDataSource
Set iDsrc = iMsg  ' (QueryInterface)

In the first case, when setting the variable iMsg to a new instance of the Message COM class, Visual Basic internally calls QueryInterface to retrieve the IMessage interface on the object. In the next case, Visual Basic calls QueryInterface to retrieve the IDataSource interface on the object.

Visual Basic only works with interfaces that are oleautomation compatible; interfaces that are oleautomation-compatible are normally marked in the type library with the oleautomation attribute.

Note   The distinction between an object and an interface on an object is not noticeably apparent using Visual Basic. Most objects only expose one interface that is oleautomation compatible, and normally this interface is dual. However, ADSI and CDO objects expose multiple oleautomation-compatible interfaces on many objects. Wherever possible, the distinction between interface and object is preserved in this documentation.