Search code examples
c#c++dllcomdllregistration

Unmanaged C++ to call C# dll with automatic registration when buildning or without COM?


I have a function in C++ that needs to call a C# dll. The C++ function simply sends values to the C# dll functions. The C# dll uses these values to produce some files and then finishes.

My problem is that when using COM I need to register the DLL everytime when using a different computer. So, is there any way to register the dll file and produce a .tlb file on build?

copy $(TargetPath) $(TargetDir) C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe $(TargetPath) /codebase CReportGenerationDLL.dll /tlb:CReportGenerationDLL.tlb

This is what i have tried, but it wont work.. I get exited with code 9009

//Pewdut


Solution

  • If your meaning is to register your COM object automatically each time when building your application on another compputer, then the answer is (assuming you are using VS2010 for building) : Go to Project/Properties/Build events and add to the "Post-build event command line" the following line:

    regasm <path to your COM .dll>
    

    If your meaning is to register your COM object automatically each time when running your application on another compputer, then you can create a batch file which contains:

    regasm <path to your COM .dll>
    <path to your application>app.exe"
    

    Or just call regasm.exe from your application using ShellExecute function.

    You may want to add /s switch to make the registration silent.

    Error 9009 says that your path to regasm is wrong, see here

    copy $(TargetPath) $(TargetDir) is out of place, why do you need this, what are you trying to achieve?