When the 'Open MXD' button is used in the EngineControls sample(to switch from MXD with a custom layer to a blank MXD), the custom layer is not being unloaded properly.
Need to clear the ActiveView when the OnPageLayoutReplaced event is calledHere are the code changes for a workaround. In the file EngineControlsDlg.cpp - HRESULT CEngineControlsDlg::OnPageLayoutReplaced(VARIANT newMap){ if(m_ipPageLayout) { m_ipPageLayout ->Clear(); } m_ipPageLayoutControl->get_ActiveView(&m_ipPageLayout); // Get the IActiveView of the focus map in the PageLayoutControl IActiveViewPtr ipActiveView; m_ipPageLayoutControl->get_ActiveView(&ipActiveView); In the file EngineControlsDlg.h – // The Controls IToolbarControlPtr m_ipToolbarControl; IToolbarControlPtr m_ipMapToolbarCtrl; ITOCControlPtr m_ipTOCControl; IMapControl3Ptr m_ipMapControl; IPageLayoutControl2Ptr m_ipPageLayoutControl; IActiveViewPtr m_ipPageLayout;