Using CoCreateInstance

At times you may need to create a COM object for a given AcDbObjectId or AcDbObject pointer. This can be done by using CoCreateInstance to create the object, and then calling AcAxOleLinkManager and IAcadBaseObject functions to set up the appropriate links. As an alternative, you can use the following exported global functions to do this work for you:

// Get the IUnknown of the existing COM object (or newly created COM
// object if one does not exist) that represents the AcDbObject
// passed in.
// 
HRESULT
AcAxGetIUnknownOfObject(LPUNKNOWN* ppUnk, AcDbObjectId& objId,
    LPDISPATCH pApp);
HRESULT
AcAxGetIUnknownOfObject(LPUNKNOWN* ppUnk, AcDbObject* pObj,
    LPDISPATCH pApp);

In addition to creating a new COM object, these functions establish two-way linking between the COM object and its AutoCAD counterpart.