views:

46

answers:

2

I am creating a C# winforms application targeting the .NET 3.5 framework. I want this program to be able to have plugins. Hopefully the plugins can be created in unmanaged C++. If there is no direct way to make a plugin in C++, then i would like the know the easiest plugin framework that would allow me to make a simple C# wrapper for the C++ code and turn that into a plugin.

I have been researching some possible plugin frameworks, and i was wondering what your guy's feeling is about this.

  • System.Addin namespace
  • MEF
  • Mono.Addins

Additional Info: I want this to be all-purpose. For example, i would like c# program to be able to handle plugins that are written in C#, an sdk written in C++ with C# swig bindings, maybe some straight up unmanaged C++ code, and possibly some python. Again, some sort of wrapper is probably necessary.

Also i would like to point out that i have never dealt with plugins before, so this is all new to me.

+1  A: 

Well, you can just define the methods you want the plugin to implement, then load plugin dll using LoadLibrary and get pointers to needed methods using GetProcAddress. Just write a small wrapper class that will get dll name in c'tor and expose needed interface in .Net, but will forward all calls to the dll.

You do not need any framework for this wrapper.

Alex Reitbort
@user380527: Also, if you can help it, load the plugin into its own restricted AppDomain.
Merlyn Morgan-Graham
A: 

What I suggest that you do is to create an interface for the addins (or use like System.Addins). Then create a sample addin in Managed C++ that just loads the dll using LoadLibrary and wires up the functions of the same name to their managed equivalents. You can then manage the marshalling yourself.

Then you can use a simple c# decorator around this to load any DLL addin specifically.

Preet Sangha