coclass

Why is it possible to create a new instance of a COM interface?

元气小坏坏 提交于 2019-12-19 16:13:12
问题 I don't have very much background regarding COM nor coclasses, so I don't quite understand why I can use the new operator with an interface. From a language/framework-agnostic view, it's confusing why this compiles and runs correctly: using Microsoft.Office.Interop.Excel; public class ExcelProgram { static void Main(string[] args) { Application excel = new Application(); } } Inspecting Application in Visual Studio 2010 shows me: using System.Runtime.InteropServices; namespace Microsoft.Office

Why is it possible to create a new instance of a COM interface?

☆樱花仙子☆ 提交于 2019-12-19 16:13:07
问题 I don't have very much background regarding COM nor coclasses, so I don't quite understand why I can use the new operator with an interface. From a language/framework-agnostic view, it's confusing why this compiles and runs correctly: using Microsoft.Office.Interop.Excel; public class ExcelProgram { static void Main(string[] args) { Application excel = new Application(); } } Inspecting Application in Visual Studio 2010 shows me: using System.Runtime.InteropServices; namespace Microsoft.Office

Is it ok to (ab)use CoClassAttribute to provide a default implementation for an interface?

こ雲淡風輕ζ 提交于 2019-12-01 05:03:23
问题 I recently discovered that it's possible to "new up" an interface in C# by decorating the interface with the CoClassAttribute to specify a default implementation. [ComImport, Guid("579A4F68-4E51-479A-A7AA-A4DDC4031F3F"), CoClass(typeof(FooImpl))] public interface IFoo { void Bar(); } public class FooImpl : IFoo { public void Bar() { } } ... // Constructs a FooImpl IFoo foo = new IFoo(); I'm aware that this feature exists primarily to support COM-interop, but I was wondering if this would be a

What does the C# CoClass attribute do?

限于喜欢 提交于 2019-11-30 12:39:41
问题 I found code something like the following in a 3rd party library we're using. [CoClass(typeof(BlahClass))] public interface Blah : IBlah { } What is this doing exactly? The msdn documentation didn't illuminate the subject sufficiently for me to follow. 回答1: It declares that the interface Blah is intended to be implemented by a specific class. It means that you can conveniently say new Blah and the runtime will know what object to create - something that is not normally possible with an

What does the C# CoClass attribute do?

你说的曾经没有我的故事 提交于 2019-11-30 03:07:34
I found code something like the following in a 3rd party library we're using. [CoClass(typeof(BlahClass))] public interface Blah : IBlah { } What is this doing exactly? The msdn documentation didn't illuminate the subject sufficiently for me to follow. It declares that the interface Blah is intended to be implemented by a specific class. It means that you can conveniently say new Blah and the runtime will know what object to create - something that is not normally possible with an interface. If you look at the generated declaration for BlahClass, it will presumably have a Guid associated with