// try to get the active calculator before creating a new one
LPUNKNOWN lpUnk;
LPDISPATCH lpDispatch;
if (GetActiveObject(clsid, NULL, &lpUnk) == NOERROR)
{
HRESULT hr = lpUnk->QueryInterface(IID_IDispatch,(LPVOID*)&lpDispatch);
lpUnk->Release();
if (hr == NOERROR) m_acadApp.AttachDispatch(lpDispatch, TRUE);
}
// if not dispatch ptr attached yet, need to create one
if (m_acadApp.m_lpDispatch == NULL &&
!m_acadApp.CreateDispatch(clsid))
{