<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Locating AddIn Extension from a Button in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241866#M6258</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Communication between types within an add-in &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Within most Add-In projects, some means for inter-component communication is needed so that one component can activate or obtain state from another; for example, a particular Add-In Button component�??when pressed�??may alter the overall Add-In state in a way which modifies the content displayed within an associated Add-In Dockview component.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the past, many developers have resorted to using COM based mechanisms for inter-component communication, defining custom interfaces which are then exposed from Button, Dockview or Extension components.&amp;nbsp; These interfaces are accessed by first finding the component using framework supplied find functions�??ICommandBar.Find, IApplication.FindExtension, etc.&amp;nbsp; The returned reference is then cast to the custom interface and used.&amp;nbsp; There are several downsides associated with this approach:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Using COM interfaces restricts communication to the simple types and calling patterns supported by COM and rules out the use of any language specific types and patterns.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;LI&gt;Communication between components within the same project is generally private; registering COM interfaces ostensibly publicizes these private communication lines and unnecessarily complicates any public interfaces intended for exposure outside the project. &lt;/LI&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;LI&gt;COM interfaces need additional non-trivial coding steps and require registration within the system registry by an installer with administrative rights.&amp;nbsp; In .NET, such interfaces also require the generation and registration of Primary Interop Assemblies which introduce multiple native/managed context switches for each call (even though both ends of the conversation are managed).&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;SPAN&gt;Since, by design, Add-Ins cannot themselves rely on COM patterns and do not require registration, the traditional approach using COM isn�??t a viable option.&amp;nbsp; The alternative pattern is much more straightforward and has none of the associated downsides listed above.&amp;nbsp; Since all framework types are singletons, Add-In developers can use a simple approach based on static class members to achieve inter-component communication.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following example demonstrates how an extension can directly expose its functionality to other components within the same project:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public class MainExt : ESRI.ArcGIS.Desktop.AddIns.Extension
{
&amp;nbsp; private static MainExt s_extension;

&amp;nbsp; public MainExt()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; s_extension = this;
&amp;nbsp; }

&amp;nbsp; internal static MainExt GetExtension()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Extension loads just in time, call FindExtension to load it.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (s_extension == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UID extID = new UIDClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extID.Value = "ACME_MainExt";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ArcMap.Application.FindExtensionByCLSID(extID);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return s_extension;
&amp;nbsp; }

&amp;nbsp; internal void DoWork()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Windows.Forms.MessageBox.Show("Do work");
&amp;nbsp; }
}&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Client code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;protected override void OnClick()
{
&amp;nbsp; MainExt mainExt = MainExt.GetExtension();
&amp;nbsp; mainExt.DoWork();
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:07:57 GMT</pubDate>
    <dc:creator>SteveVan_Esch</dc:creator>
    <dc:date>2021-12-11T12:07:57Z</dc:date>
    <item>
      <title>Locating AddIn Extension from a Button</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241865#M6257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How do I locate my AddIn Extension to use functionality within the code of an AddIn Button correctly. The "ArcMap.Application.FindExtensionByName(...)" is working, but I receive an IExtension Interface and its not possible to cast to other interfaces implemented into the AddIn Extension. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IExtension ext = ArcMap.Application.FindExtensionByName("myDemoExt");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IDemoExt demoExt = (IDemoExt)ext;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I receive the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Unable to cast COM object of type 'System.__ComObject' to interface type 'Demo.IDemoExt'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C1DA7464-AAA7-3B1E-8B02-BB571D92E278}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My AddIn Extension looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;public class DemoExt : ESRI.ArcGIS.Desktop.AddIns.Extension, IDemoExt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 14:02:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241865#M6257</guid>
      <dc:creator>JochenManegold</dc:creator>
      <dc:date>2010-01-04T14:02:48Z</dc:date>
    </item>
    <item>
      <title>Locating AddIn Extension from a Button</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241866#M6258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Communication between types within an add-in &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Within most Add-In projects, some means for inter-component communication is needed so that one component can activate or obtain state from another; for example, a particular Add-In Button component�??when pressed�??may alter the overall Add-In state in a way which modifies the content displayed within an associated Add-In Dockview component.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the past, many developers have resorted to using COM based mechanisms for inter-component communication, defining custom interfaces which are then exposed from Button, Dockview or Extension components.&amp;nbsp; These interfaces are accessed by first finding the component using framework supplied find functions�??ICommandBar.Find, IApplication.FindExtension, etc.&amp;nbsp; The returned reference is then cast to the custom interface and used.&amp;nbsp; There are several downsides associated with this approach:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Using COM interfaces restricts communication to the simple types and calling patterns supported by COM and rules out the use of any language specific types and patterns.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;LI&gt;Communication between components within the same project is generally private; registering COM interfaces ostensibly publicizes these private communication lines and unnecessarily complicates any public interfaces intended for exposure outside the project. &lt;/LI&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;LI&gt;COM interfaces need additional non-trivial coding steps and require registration within the system registry by an installer with administrative rights.&amp;nbsp; In .NET, such interfaces also require the generation and registration of Primary Interop Assemblies which introduce multiple native/managed context switches for each call (even though both ends of the conversation are managed).&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;SPAN&gt;Since, by design, Add-Ins cannot themselves rely on COM patterns and do not require registration, the traditional approach using COM isn�??t a viable option.&amp;nbsp; The alternative pattern is much more straightforward and has none of the associated downsides listed above.&amp;nbsp; Since all framework types are singletons, Add-In developers can use a simple approach based on static class members to achieve inter-component communication.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following example demonstrates how an extension can directly expose its functionality to other components within the same project:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public class MainExt : ESRI.ArcGIS.Desktop.AddIns.Extension
{
&amp;nbsp; private static MainExt s_extension;

&amp;nbsp; public MainExt()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; s_extension = this;
&amp;nbsp; }

&amp;nbsp; internal static MainExt GetExtension()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Extension loads just in time, call FindExtension to load it.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (s_extension == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UID extID = new UIDClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extID.Value = "ACME_MainExt";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ArcMap.Application.FindExtensionByCLSID(extID);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return s_extension;
&amp;nbsp; }

&amp;nbsp; internal void DoWork()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Windows.Forms.MessageBox.Show("Do work");
&amp;nbsp; }
}&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Client code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;protected override void OnClick()
{
&amp;nbsp; MainExt mainExt = MainExt.GetExtension();
&amp;nbsp; mainExt.DoWork();
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:07:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241866#M6258</guid>
      <dc:creator>SteveVan_Esch</dc:creator>
      <dc:date>2021-12-11T12:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Beta 10: Locating AddIn Extension from a Button</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241867#M6259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I know it's been awhile since this issue was posted, but I wanted to follow-up to determine if it is still possible to find an AddIn Extension the "old fashion" way (i.e. via the COM QueryInterface mechanism).&amp;nbsp; The reason I ask is because the "new" way forces me to add a direct reference to the AddIn Extension project/assembly that I want to use, whereas with the "old" way, I only had to add a reference to the project/assembly defining the "interface" that I wanted to use.&amp;nbsp; Several of your own examples show how to do it the "old" way (i.e. the PointsALongLineTool sample): &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //get the editor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UID editorUid = new UID();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; editorUid.Value = "esriEditor.Editor";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IEditor3 editor = m_application.FindExtensionByCLSID(editorUid) as IEditor3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So of course, I would like to do something similar with my extension (such as "jm" reqested in the original post):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IExtension ext = ArcMap.Application.FindExtensionByName("myDemoExt");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDemoExt demoExt = (IDemoExt)ext;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What do I need to do to my Extension class to make this possible?&amp;nbsp; I'm sure it probably involves using the COM interoperable stuff such as ComVisible, Guid, ClassInterface, ProgId, ComRegisterFunction, ComUnregisterFunction, etc.&amp;nbsp; Any help with this would be much appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Jan 2013 20:47:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241867#M6259</guid>
      <dc:creator>DonParker</dc:creator>
      <dc:date>2013-01-02T20:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Beta 10: Locating AddIn Extension from a Button</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241868#M6260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I currently having a similar problem: I need to access the extension residing inside my AddIn to be access from an outside, old-fashion COM component. I can get the AddIn extension by using FindExtensionByName, but then I can't cast it to my custom interface (implemented in the same class as the AddIn-Extension). Is that even possible, Esri? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 13:32:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/locating-addin-extension-from-a-button/m-p/241868#M6260</guid>
      <dc:creator>AndryJoos</dc:creator>
      <dc:date>2013-02-05T13:32:33Z</dc:date>
    </item>
  </channel>
</rss>

