Search code examples
c#c++.netdllcom

Using C# dll in C++ codes without using Regasm


I have created a C++ application which uses a C# dll following the link as shown below.

http://support.microsoft.com/kb/828736

The application works fine on my development PC , but when I tried to run it on another PC , it fails.

The only way to make it work is to recompile the C# dll on that PC and run the Regasm command again on that PC to work .

Is there a way to build my C# dll in such a way so that I do not have to do this every single time on every PC my application is deployed to ?


Solution

  • What regasm does is generate a COM wrapper for your C# dll and then registers it as a COM object.

    You do not need to recompile though, once you have a dll you can register it on the target PC using regasm.

    The main other way to call a C# dll is to write a C++ .net program using the C++/CLI system from Microsoft. This is basically a way of creating .NET programs using a superset of C++ (hint: its not C++, which is a shame as the old managed extensions it replaces was much more transparent for this task). As its not 'true' C++ you'll end up with a .NET binary instead of a C++ one, so be aware of this. One aspect is that you could write a C++/CLI wrapper to the C# dll and call that from your C++ program, this is probably the preferred way of creating a bridge between the systems.