开发者

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

开发者 https://www.devze.com 2023-03-31 13:59 出处:网络
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# pl

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

精彩评论

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

关注公众号