AutoCAD communicates with its ActiveX Automation object model by creating a link between a database-resident object (AcDbObject) and a COM object that represents it. This link is composed of two one-directional pointers. The first pointer references the IUnknown of the COM object. It is stored using a transient reactor on the AcDbObject. The second pointer is the AcDbObjectId of the database-resident object, which is stored as a member variable on the COM object.
The IUnknown link allows you to retrieve the existing IUnknown pointer of the COM object from an AcDbObject pointer, as shown in the following code:
AcAxOleLinkManager* pOleLinkManager = AcAxGetOleLinkManager(); // pObject is an AcDbObject* // IUnknown* pUnk = pOleLinkManager->GetIUnknown(pObject); // NOTE: AcAxOleLinkManager::GetIUnknown() does not AddRef() // the IUnknown pointer.
Conversely, you can retrieve the AcDbObjectId of the database-resident object being represented by a COM object from an interface pointer, as shown in the following code:
IAcadBaseObject* pAcadBaseObject = NULL; // pUnk is the IUnknown* of a COM object representing // some object in the database // HRESULT hr = pUnk->QueryInterface(IID_IAcadBaseObject, (LPVOID*) &pAcadBaseObject); AcDbObjectId objId; if(SUCCEEDED(hr)) { pAcadBaseObject->GetObjectId(&objId); }