C ++ Extension - Applications with C # Plugins

I have a C ++ Windows application that can be extended by writing C ++ plugins using the API that the application opens. There is also one plugin that translates the C ++ API to Python (for example, plugins can be written in Python).

I want to allow users to write plugins in C # in addition to C ++ and Python. Since I am not very familiar with the .NET world, I am not sure how to implement the C # plugin system.

What do you recommend using for this kind of plugins (host C ++, plugins C #)? What do I need to study in order to achieve this?

+1


source to share


4 answers


There are several previous posts that may help you:



+3


source


Open your API with COM objects and interfaces, and you will open your application in many development environments including C #.



+3


source


Actually as well as COM suggestions. If you really want to add support for class 1 .NET plugins, you can host your own CLR process. There is a very interesting article here.

http://msdn.microsoft.com/en-us/magazine/cc163567.aspx

+2


source


I've done this in different ways in the past. I found that C ++ / CLI was the best option for building a bridge between .Net and unmanaged C ++ (although, as other posters have pointed out, COM is in a different variation).

I've used the following methods in the past:

  • Generating C ++ / CLI API wrapper code from my C ++ API using reflection. Of course, native C ++ doesn't have a reflection system, so we skated on our own. The generated C ++ / CLI code was then compiled into an assembly that the C # plugin would reference.
  • Generating a dynamic assembly from my C ++ API using reflection (i.e. using Reflection.Emit stuff). The resulting assembly can be used in-process for scripting languages, or you can even compile C # code against it at runtime. The assembly can even be written to disk for use statically. The downside here is that you probably can't emit better IL than the compiler, so if you don't need dynamic generation, don't go that route.
  • C ++ / CLI API handwritten wrappers. If the API is not very large, writing the cover by hand is easy enough.

You will end up with a build for C # plugins to compile. Now you need to load the plugin assemblies at runtime. To do this, you must host the CLR.

Hosting the CLR isn't difficult, although I only did it once and that was a few years ago - maybe times have changed. If you are not comfortable hosting the CLR, then insert your application code into DLLs as soon as possible, and then write a small C ++ / CLI application that will result in an unmanaged user interface. The CLR is now hosted by a small C ++ / CLI application.

+1


source







All Articles