Overriding the dropCallback() Method

Much of the code needed to manage multiple dropped objects is provided in the AcadToolImpl implementation of the IAcadToolDropTarget::Drop() method. This implementation processes the objects in the Clipboard data and calls your dropCallback() method for each entity found. Your dropCallback() method should examine the entity's type and decide whether to accept the drop. If you accept a dropped entity, you simply set the tool's internal property variables to values obtained from the dropped entity.

Typically, your application accepts its own custom entity types. The tool you create specializes one of your stock tools by assuming property settings from the dropped object. When the user clicks the new tool, you create a new instance of your custom entity that matches the dropped object's characteristics. You should not open or close objects passed to your dropCallback() function. AcadToolImpl opens objects for read before calling your function, and closes them when your function returns.

The following listing shows a sample AcadToolImpl::dropCallback() implementation:

STDMETHODIMP CBoltTool::dropCallback(AcDbEntity *pDropEntity)
{
// Cast the pointer first, and make sure it is successful.
asdkBolt *pBolt=(asdkBolt*)asdkBolt::cast(pDropEntity);
if(pBolt)
{
    m_Color.setColor(pBolt->color().color());
    m_Color.setNames(pBolt->color().colorName(), 
        pBolt->color().bookName());
    _tcscpy(m_szLayer,CA2T(pBolt->layer()));
    _tcscpy(m_MaterialName,CA2T(pBolt->materialName));
    _tcscpy(m_PartNumber,CA2T(pBolt->partNumber));
    m_HeadSides=pBolt->getHeadSides();
    m_HeadHeight=pBolt->getHeadHeight();
    m_ShaftLength=pBolt->getShaftLength();
    m_ShaftDiameter=pBolt->getShaftDiameter();
    m_ThreadLength=pBolt->getThreadLength();
    m_ThreadWidth=pBolt->getThreadWidth();
    m_HeadDiameter=pBolt->getHeadDiameter();
    return S_OK;
}
return E_FAIL;
// You don't need to worry about closing the object passed in.
}