I using Visual Studio 2010 (.NET 4). I need to create a COM object (in C#) and have no idea how to get started (what type of project to use,etc.)
To expose properties and methods to COM, you must declare them on the class interface and mark them with a DispId attribute, and implement them in the class. The order in which the members are declared in the interface is the order used for the COM vtable.
Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
OK I found the solution and I'll write it here for the common good.
using System.Runtime.InteropServices;
to the file now you can use your COM object by using it's ProgID.
example: the C# code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace Launcher { [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")] public interface ILauncher { void launch(); } [ClassInterface(ClassInterfaceType.None), Guid("YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYY"), ProgId("Launcher.Launcher")] public class Launcher : ILauncher { private string path = null; public void launch() { Console.WriteLine("I launch scripts for a living."); } } }
and VB script using the COM:
set obj = createObject("PSLauncher.PSLauncher") obj.launch()
and the output will be:
I launch scripts for a living
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With