{"id":2573,"date":"2006-01-16T14:44:00","date_gmt":"2006-01-16T14:44:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2006\/01\/16\/guidelines-for-com-interoperability-from-net-update-1\/"},"modified":"2006-01-16T14:44:00","modified_gmt":"2006-01-16T14:44:00","slug":"guidelines-for-com-interoperability-from-net-update-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/guidelines-for-com-interoperability-from-net-update-1\/","title":{"rendered":"Guidelines for COM Interoperability from .NET (Update 1)"},"content":{"rendered":"<p>Sometime back I posted\n<a href=\"http:\/\/blogs.msdn.com\/heaths\/archive\/2005\/03\/09\/391358.aspx\">Guidelines for COM Interoperability from .NET<\/a> where I\nenumerated several practices to follow when exposing types from your managed\nassemblies to COM. This update is to provide some additional information with\nthe release of the Microsoft .NET Framework 2.0 as well as correct one statement\nI made with regard to inheritting interfaces when those interfaces are exposed\neither as automation interfaces (inheriting from <code>IDispatch<\/code>) or dual interfaces\n(inheriting both from <code>IUnknown <\/code>and <code>IDispatch<\/code>).<\/p>\n<p>Previously I mentioned that you should declare class interfaces explicitly\nand implement them as the first interface on your class attributed with the\n<code>ClassInterfaceAttribute<\/code> with the value of <code>ClassInterfaceType.None<\/code>. In the .NET\nFramework 2.0 a new attribute was added to explicitly declare which interface is\nthe default interface for the class since in some cases the provided compilers\nwill generate interfaces in a different order and third-party compilers may not\neven honor the order in the first place. The <a href=\"http:\/\/msdn2.microsoft.com\/library\/System.Runtime.InteropServices.ComDefaultInterfaceAttribute\"><code>ComDefaultInterfaceAttribute<\/code> class<\/a>\nshould be declared for your implementation class and you should specify the type\nof the class interface. The class must still implement this interface. This is\nalso necessary since the interface will always inherit from either <code>IUnknown<\/code> or\n<code>IDispatch<\/code> depending on the value you use for the <code>InterfaceTypeAttribute<\/code>\nattributed on the interface. See\n<a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/cpguide\/html\/cpconinheritanceaggregationcontainment.asp\">\nInheritance, Aggregation, and Containment<\/a> in the .NET Framework SDK for more\ninformation.<\/p>\n<p>I also mentioned that you should implement new versions of interfaces that\ninherit from older interfaces. When exposing your interfaces with\n<code>ComInterfaceType.InterfaceIsIDispatch<\/code> or <code>ComInterfaceType.InterfaceIsDual<\/code> you\nshould actually re-declare all previous members since many automation clients\nlike Windows Script can only work with a single default dispatch interface. You\nshould still implement the older versions of the interfaces but as e<a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms173157(en-US,VS.80).aspx\">xplicit\ninterface implementations<\/a>.<\/p>\n<p>Also note that there is a new namespace that you should use if you can base\nyour development and deployment with .NET 2.0 as the minimal requirement. The\n<a href=\"http:\/\/msdn2.microsoft.com\/library\/System.Runtime.InteropServices.ComTypes\">\n<code>System.Runtime.InteropServices.ComTypes<\/code> namespace<\/a> declares many\ninterfaces commonly implemented by COM servers and used by COM clients. The\ninterfaces in <code>System.Runtime.InteropServices<\/code> that begin with <code>UCOMI<\/code>* are obsolete\nand may be removed in future versions as well.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometime back I posted Guidelines for COM Interoperability from .NET where I enumerated several practices to follow when exposing types from your managed assemblies to COM. This update is to provide some additional information with the release of the Microsoft .NET Framework 2.0 as well as correct one statement I made with regard to inheritting [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[14],"class_list":["post-2573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-development"],"acf":[],"blog_post_summary":"<p>Sometime back I posted Guidelines for COM Interoperability from .NET where I enumerated several practices to follow when exposing types from your managed assemblies to COM. This update is to provide some additional information with the release of the Microsoft .NET Framework 2.0 as well as correct one statement I made with regard to inheritting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=2573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=2573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=2573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=2573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}