开发者

How to dynamically load a managed (.Net) DLL in unmanaged code?

How to dynamically load a managed (.Net) DLL in unmanaged code?

I'm creating a plugin system in C++ that gets injected i开发者_Python百科nto an application and I would like to be able to write C# plugins.

I've searched a bit but could only find COM loading (with #import), but I don't know how to do that at runtime, if it's possible.

The C# DLL (Plugin) could call functions in the C++ DLL (Plugin Manager).

I would prefer a solution that doesn't require me to compile the C++ DLL with /clr.


There are multiple issues here.

I would prefer a solution that doesn't require me to compile the C++ DLL with /clr.

At some level, to use a C# DLL, you'll need to bootstrap the CLR. Using /clr has a huge advantage - you can provide a truly managed API for the C# plugin to work against.

Your main other options are to either use COM, and provide a COM based API. This will work fine from C# as well as other languages, and take care of loading the CLR for you. The only other API is to self-host the CLR using the hosting APIs. This provides you the most control, but is definitely a fair amount of extra work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜