Data Objects and MMC 2.0

Data transfer within MMC is accomplished using the COM interface IDataObject, which snap-ins implement. The actual data is shared in clipboard formats. The IDataObject interface includes methods that enable data to be transferred and notifications to be generated when data changes.

MMC uses the IDataObject::GetDataHere and IDataObject::GetData methods to get data from scope and result items. The IDataObject interface and its methods are documented in the Platform Software Development Kit (SDK).

All data that is transferred resides in global memory, so the TYMED identifier of the STGMEDIUM structure passed to a data object in the IDataObject::GetDataHere method is always an HGLOBAL.

MMC frequently requests snap-ins to provide data objects by calling their IComponentData::QueryDataObject or IComponent::QueryDataObject method. For this reason, snap-in developers should ensure that this is an efficient operation.

One technique for improving efficiency is to implement a pool of data objects that can be used more than once to fulfill common MMC data requests. These data objects exist for the lifetime of a snap-in instance. When MMC requests data that be provided by one of these data objects, the snap-in supplies that data object to MMC and increments its reference count. This technique is based on the fact that data objects are COM objects; MMC simply releases its interface to a data object after it is no longer required.

The following sequence diagram written in UML(Unified Modeling Language) illustrates the general method by which MMC requests a data object from a snap-in. In the diagram, MMC calls the data object's GetDataHere method to request data in a specific clipboard format.

mmc requesting a data object from a snap-in

In the scenario depicted in the diagram, MMC calls the QueryDataObject method of CComponentData, which implements the MMC interface IComponentData. One of the arguments of QueryDataObject is the cookie value of the node for which MMC is requesting data. CComponentData creates a data object and passes the cookie to it. MMC then calls the GetDataHere method of the data object and specifies the required clipboard format in which the data object should render the requested data. The data object in the diagram delegates the data rendering to a delegation base. This is the preferred implementation.

The data object then writes the requested data back into the stream created by using the HGlobal handle provided to it by MMC in GetDataHere. After using the data and at an appropriate time, MMC releases the interface pointer to the data object with a call to the object's Release method.