IEXTENSION INTERFACE

774
2
03-11-2013 08:13 PM
ChaitanyaPeddinty
New Contributor
// Code in  ext.cs


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.esriSystem;

namespace NE_EXT
{
    /// <summary>
    /// Summary description for NEConvertExt.
    /// </summary>
    [Guid("d1bb6202-5f18-4509-977c-79aecfbf9c62")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("NE_EXT.NEConvertExt")]
    public sealed class NEConvertExt : IExtension
    {       

        private IApplication m_application;
        IMxDocument pMxDoc;
        string sMxdFileName = "C:\\Documents and Settings\\abc\\Desktop\\mXD'S\\abc.mxd";
       
       
        #region IExtension Members

        public string Name
        {
            get
            {
                return "ConvertToNEExtension";
            }
        }

        public void Shutdown()
        {
            //throw new NotImplementedException();
            m_application = null;
        }

        public void Startup(ref object initializationData)
        {
            m_application = initializationData as IApplication;
            if (m_application == null)
                return;
        }

        #endregion


        public void CreateWorkorder(string WoName,string WoType)
        {            
        }
        public void OpenWorkorder(string WoName)
        {
        }
        public void Convert(string strServer,string strInstance,string strUserName,string strVersion)
        {
        }

I wrote above code in IExtension class.




I want to access these Methods in another External Application ,for That

// Code in EXtApp.cs

if (!b_ArcMapStarted)
                    {
                        IDocument pDoc = new MxDocumentClass();
                        pApp = pDoc.Parent();
                        pApp.OpenDocument(sMxdFileName);//Opened a saved Mxd

                        pApp.Visible = false;

                       IExtension objExt; // Created I Extension Object
                        objExt = pApp.FindExtensionByName("ConvertToNEExtension");
                        if (objExt != null)
                        {
                            objExt.c// Here that methods are not accesible, I didn't get  what's the problem is
                        }
0 Kudos
2 Replies
RichardWatson
Frequent Contributor
This is a COM interop problem.

It does not look like you exposed the class, i.e. ClassInterface(ClassInterfaceType.None).

If want to see what is exposed then use OleView and view the generated type library.  If the functions you want are not in the type library then they won't be exposed to COM.
0 Kudos
AlexanderGray
Occasional Contributor III
I have always done this by defining my own custom interface for the methods I need to call from another assembly.  I implement both IExtension and my own custom interface on the class.  Then If I add a reference to the first assembly in my external assembly, I can cast the IExtension variable to my custom extension and use the methods on it.
0 Kudos