Using .NET Components from within COM

We can use .NET code from within COM and proxy called COM Callable Wrapper (CCW) is responsible for this interoperability. If we don’t want to have all methods visible in COM we simply set attribute like that

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DemoCS
{
    [ComVisible(false)]
    class Person
    {
        private String lName;
        private Int32 salary;
      [ComVisible(true)]
      public String LName
      {
          get { return lName; }
          set { lName = value; }
      }
      [ComVisible(false)]
      public Int32 Salary
      {
          get { return salary; }
          set{salary = value}
      }
   }
}

There are guidelines then creating COM Assemblies suggested my Microsoft. They suggest that all classes should have default constructor without parameters, all exposed types and members must be public, and abstract classes will not be able to consume.

We can export Assemblies with Visual Studio 2005 or a command-line utility tool (TlbExp.exe).