On .NET/COM Interoperability

I. Deploying a .NET Application for COM Access

  1. Create a .NET assembly containing a class that will be called by a COM client.
    Keep in mind a special requirement for the .NET code structure:

    • the .NET code should export a signed interface
      public interface INETCode
      // exposed properties and methods

    • In the .NET class, the INETCode interface should be the first interface implemented in the class declaration:

      public class NETCode : System.Windows.Forms.UserControl, INETCode
      // implementation exposed methods for properties getter/setters.

  2. Create a key pair and use it to sign the assembly to make the assembly globally available.
    To make it easier to work with the assembly one can add a title and description.
    To sign the assembly, one can run the sn utility and add the name of the key file by hand,
    or you can generate a strong name using the Visual Studio .NET user interface
    by edditing the <assembly-nameInfo>.vb file.

  3. Create a type library for the assembly (.tbl) with tblexp:
    tlbexp <assembly-name>.dll /out:<table-name>.tlb

  4. Register the type library (also creates the library itself).
    For it use the Assembly Registration Tool regasm from the .NET Framework SDK:
    regasm /tlb:<table-name>.tlb <assembly-name>.dll

  5. Install the .NET assembly into the Global Assembly Cache (GAC)
    so that it will be available as a shared assembly. To install an assembly into the GAC, use the gacutil tool:
    gacutil /i<assembly-name>.dll

II. Check the DLL generated

  • to see all functions that DLL exports, type in VS comand promt
    link /dump /exports <libname>.dll
    I'm sure there is a more elegant way to do it, but this one works as well

III. Calling a .NET assembly from within Visual C++ COM code