Friday, April 8, 2011

COM to .NET

How to make a .NET class library be accessible as a COM object?
  1. Create a new .net class library project for the wrapper
  2. Declare the class as "ComVisible":
    using System.Runtime.InteropServices;
    [ComVisible( true )] public class ClassName
  3. Generate the Keyfile:
    C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\sn.exe -k "keyfile.snk"
  4. Set the project property to sign the library using the generated keyfile
  5. Generate the Registry entry with the path to the library .dll as the "codebase":
    regasm.exe %TRGDIR%\LibName.dll /codebase
    Specify also the /tlb option if the library is to be imported by the C++ #import directive
  6. Check the registry has the ProgId: LibName.ClassName and refers to the CLSID which has the "codebase" path to the LibName.dll

No comments:

Post a Comment