Cookies and Inserting Items
Snap-ins insert items into the scope or result pane using the IResultData::InsertItem or IConsoleNameSpace2::InsertItem method. The cookie value of the inserted item is stored in the lParam member of the SCOPEDATAITEM structure (for scope items) or RESULTDATAITEM structure (for result items).
After an item is successfully inserted, MMC calls IComponentData::GetDisplayInfo or IComponent:GetDisplayInfo, depending on which object inserted the item. The snap-in can then cast the lParam (cookie) back into the reference for the selected item and retrieve the display name, image index, or other information that can be displayed in the result pane's columns.
As previously mentioned, MMC often requests data objects from snap-ins by calling the IComponentData::QueryDataObject or IComponent::QueryDataObject method. In the call to QueryDataObject, MMC also passes the cookie value of the item for which MMC requires data. If the requested data object is created to notify a snap-in of a user action on a particular scope or result item, MMC forwards the data object back to the snap-in, along with the appropriate notification message. The only way that the snap-in can properly identify the affected item is by means of the cookie value that is passed into the call to the QueryDataObject method.
It is therefore very important that any implementation of IDataObject stores the cookie value of the item for which MMC is requesting a data object.