Platform SDK: CDO for Windows 2000

Navigating CDO Interfaces with VBScript

Unlike the ActiveX Data Objects (ADO) object model, CDO for Windows 2000 is an interface-driven object model. VBScript, like most scripting languages, provides no inherent mechanism for interface navigation, so CDO COM interfaces have been designed to provide this mechanism. The GetInterface method acts as IUnknown::QueryInterface on the object. One common example is the CDO IMessage interface. Objects that expose the IMessage interface normally also expose the IDataSource and IBodyPart interfaces as well. You can use IMessage.GetInterface to navigate to these interfaces using scripting languages (or any time you can access the object through the IDispatch interface).

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iDsrc
Set iDsrc = iMsg.GetInterface("IDataSource")
Dim iBp
Set iBp = iMsg.GetInterface("IBodyPart")

Many CDO interfaces also expose properties that return interfaces on the same object. Using the IMessage interface example again, the IDataSource and IBodyPart interfaces are accessible using the IMessage.DataSource and IMessage.BodyPart properties:

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iDsrc
Set iDsrc = iMsg.DataSource
Dim iBp
Set iBp = iMsg.BodyPart

In this case, you can use either the corresponding property on the interface, or the GetInterface method to navigate these interfaces.

You cannot access interfaces on objects that are not Automation-compatible. For example, to allow C++ programmers access to raw OLE DB interfaces for items, instances of the CDO Message COM class expose the OLE DB IRow interface. This interface cannot be used by scripting languages and therefore is never returned by a property on an interface or through GetInterface. It is of course accessible through QueryInterface.