Platform SDK: CDO for Windows 2000

Navigating CDO Interfaces with Visual Basic

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 as shown in the following examples:

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

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

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

Visual Basic only works with interfaces that are Automation-compatible; these 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 very apparent using Visual Basic because most objects expose only one interface that is Automation-compatible. Therefore, most Visual Basic applications have only one type of object reference to such objects. However, the CDO Message object exposes multiple Automation-compatible interfaces.