AnsweredAssumed Answered

eDrawings EModelView API

Question asked by Andrew Johnson on Nov 22, 2017
Latest reply on May 14, 2018 by Zhu Gq

I'm attempting to embed the EModelView ActiveX control into my application. I am using the 'Non-Version Specific' CLSID to instantiate the control, but the application only works correctly if the version of EDrawings on the PC matches the version of the Interop DLL I used to compile my application. If I run the application on a computer using a different eDrawings version than the Interop DLL, the application throws a COM Exception.

 

Exception Message:

Unable to cast COM object of type 'System.__ComObject' to interface type 'EModelView.x64.EModelViewControl'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C96FE0EC-F2EA-41A9-9C50-C4C6E5EB757A}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

 

ActiveX Host Control

public partial class EDrawingAxHost : AxHost
    {
        #region Fields


        private readonly bool _fullUI;
        private readonly bool _showWatermark;


        public EModelViewControl EModelViewControl;


        #endregion


        #region Constructors


        public EDrawingAxHost(bool fullUI, bool showWatermark) : base("{22945A69-1191-4DCF-9E6F-409BDE94D101}")
        {
            _fullUI = fullUI;
            _showWatermark = showWatermark;


            InitializeComponent();
        }


        #endregion


        #region Public Methods


        public void ReleaseControl()
        {
            Marshal.ReleaseComObject(EModelViewControl);
            EModelViewControl = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }


        #endregion


        #region Protected Methods


        protected override void AttachInterfaces()
        {
            EModelViewControl = (EModelViewControl) GetOcx();


            EModelViewControl.FullUI = _fullUI ? (int) EMVEnableFeatures.eMVFullUI : (int) EMVEnableFeatures.eMVSimplifiedUI;
            EModelViewControl.AlwaysShowWarningWatermark = _showWatermark ? -1 : 0;
        }


        #endregion
    }

 

UserControl that displays the ActiveX control

public partial class EDrawingControl : UserControl
    {
        private EDrawingAxHost _eDrawingAxHost;
        private EModelViewControl EModelViewControl => _eDrawingAxHost.EModelViewControl;


        public EDrawingControl(bool fullUI, bool showWatermark)
        {
            InitializeComponent();


            if (!DesignMode)
            {
                InitializeAxHost(fullUI, showWatermark);
            }
        }


        public void OpenDocument(string filepath, bool isTemp = false, bool promptToSave = false, bool isReadOnly = true, string commandString = "")
        {
            EModelViewControl.OpenDoc(filepath, isTemp, promptToSave, isReadOnly, commandString);
        }


        private void InitializeAxHost(bool fullUI, bool showWatermark)
        {
            _eDrawingAxHost = new EDrawingAxHost(fullUI, showWatermark);


            Controls.Add(_eDrawingAxHost);


            _eDrawingAxHost.Dock = DockStyle.Fill;
        }
    }

Outcomes