Skip to content

Latest commit

 

History

History
81 lines (54 loc) · 2.2 KB

README.md

File metadata and controls

81 lines (54 loc) · 2.2 KB

CRUtil

COM Registration Utility library for registering COM visible libraries on Windows.

v1.0.0

This library automatically locates and uses the RegAsm.exe utility and will register a .Net class library, passing the /tlb: command, to generate a COM visible library.

This is a personal utility that is subject to API breaking changes. Semantic versioning is used.

Example Usage:

public static void Main(string[] args)
{
    Config config = ConfigJsonReader.ReadConfiguration(@".\config.json");

    RegAsmLocation regAsmLocation = RegAsmLocation.MakeDefaultRegAsmLocation();

    DllInstaller installer = new DllInstaller();
    installer.Install(config, regAsmLocation);
}

See the Json Config File Example to manually write your configuration or save your configuration in Json format using ConfigJsonWriter:

  ConfigData configData = new ConfigData(
            libraryOrigin: @"C:\Users\PC\MyLibrary.dll",
            libraryDestination: @"C:\Windows\SysWOW64\MyLibrary.dll",
            outputFileName: @"MyLibraryForComVisibility.dll");

  ConfigJsonWriter.WriteConfiguration("installconfig.json", configData);

You may also read in the ConfigData object form your created Json file using the ConfigJsonReader.

  
  ConfigData configData = ConfigJsonReader.ReadConfiguration("installconfig.json");
  

Be sure to decorate your class library with the proper ComVisible(true) attributes:

namespace RiderLibraryTest
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    public class Class1
    {
        public Excel.Workbook ExcelWorkbook; 
       
        public Class1()
        {
        }
        
        [ComVisible(true)]
        public void Init(Excel.Workbook workbook)
        {
            ExcelWorkbook = workbook;
        }

        ~Class1()
        {
            Marshal.ReleaseComObject(ExcelWorkbook);
            ExcelWorkbook = null;
        }
    }
}

License

This project is licensed under the terms of the MIT license.