我可以创建.NET常规的Windows DLL(一个插件)?常规、插件、NET、DLL

2023-09-03 07:49:57 作者:玛丽莲猛撸

我试图创建一个插件程序。该项目工程通过加载你的插件DLL和DLL内执行特别命名的功能。 pretty的标准的东西。不过,我想创造我在C#中的插件(和我有点新手)。我的问题是,我可以导出常规C像从C#的功能呢?或者我如何轻松地创建一个存根做到这一点?

I'm trying to create a plugin for a program. The program works by loading your plugin DLL and executing specifically named functions within that DLL. Pretty standard stuff. However, I'd like to create my plugin in C# (and I am a bit of newbie). My question is, can I export regular C like functions from C#? or How do I easily create a stub to do that?

到目前为止,谷歌已经没有帮助。

So far Google has not been helpful.

推荐答案

我设法得到我想要通过下面一个相当令人费解的一系列步骤:

I managed to get what I wanted by following a fairly convoluted set of steps:

在C#的一面:

在我创建了一个C#类与接口 使得COM可见, 签订组装强名称密钥文件 用于GACUTIL到集添加到GAC 注册它与REGASM工具,并制作了TLB类型库文件。

然后,我创建了一个MFC DLL暴露,我需要导出的插件接口的功能。然后用我的C ++ code#import指令在pviously提到的TLB文件的$ P $加载。这会产生一个存根这样我就可以很容易地调用到我的C#$ C $从C ++通过COM℃。

Then I created an MFC DLL exposing the functions that I needed to export for the plugin interface. Then using the #import directive in my C++ code to load in the previously mentioned tlb file. That generates a stub so I can easily call into my C# code from C++ via COM.

结果似乎工作完美,性能瞬间(这是一个有点令人意外,我以为CLR装​​载的开销将是显着的)。

The result appears to work perfectly and the performance is instantaneous (this is a bit surprising, I assumed the CLR loading overhead would be noticeable).

加载CLR到这个特定的应用程序是不是一个真正的问题,但我关心的版本问题与其他插件。这是真的,当我做这一切通过COM关注的问题?

Loading the CLR into this particular application isn't really a problem but I am concerned about versioning issues with other plugins. Is this really a concern when I doing this all through COM?