Using C++ DLLs determined during runtime in C# -


I am currently working on the C # project and I have zero experience with C #.

We have a set of DLLs written in C ++, they have the same class and have the same functionality, but they work differently. For example, suppose our program converts BMP files, we have DLL to convert BMP to JPG, BMP and PNG.

Our programs that are written in C #, somehow wrap those dlls, but not in a steady manner. We want to be able to change the DLL in use during runtime, and if needed add new DLLs (even during runtime). Like plugins, if you will.

What would be your suggestion to implement this approach?

If you do not know that all of your DLLs are ahead of time, then you may have to "load" Libraries will need to call "GetProcAddress" and "FreeLibrary". As far as I know, there is no way to automatically do dynamic PInvoke in C # in a way. For more information, see

Alternatively, you can use PInvoke for each of your DLLs. You can create a C # wrapper and then use the managed representative to make the work call. Then, by changing the representative, you can call a different function (possibly in a different DLL) on the runtime, depending on the complete list of DLLs you use at compiled time. Although it is much stronger than the first option. This is a thousand times easier for Runtime to handle all the Marshals for you. For more information, see.

Comments