Thursday, January 10, 2008

Quick note on IDispatch, Dual & DispInterface

IDispatch Interface
The IDispatch interface was initially designed to support Automation. It provides a late-binding mechanism to access and retrieve information about an object's methods and properties(often useful in scripting languages such as VBScript, JavaScript etc).

IDispatch is designed in such a way that it can call virtually any other COM interface. Developers not working on C or C++ often cannot call COM interfaces through direct OLE VTable binding. However, when their development language supports IDispatch( e.g. as Visual Basic does) and when the object they want to call supports IDispatch, they can call its COM interfaces indirectly through IDispatch::Invoke method.

DispInterface is a pure IDispatch Interface which can not use vtable based interface. Hence DUAL attribute cant be used on dispInterface.

Dual Interfaces
OLE Automation enables an object to expose a set of methods in two ways: via the IDispatch interface, and through direct OLE VTable binding. Dual Interface supports both.

The first seven entries of the VTBL for a dual interface are the seven members of IDispatch(i.e. 4 of IDispatch and 3 of IUnknown), and the remaining entries are COM entries for direct access to members of the dual interface.


No comments: