在 VS C/C++ 中,您可以使用 extern "C"__declspec(dllexport) -function declaration-
。
如何在 C# dll 中完成此操作?是否有与上述代码等效的C#代码?
编辑:更多信息
我正在尝试为 Notepad++ 创建一个插件并且我想使用 C#,但到目前为止我看到的常见方法是使用带有上述调用的旧版 C++ 代码来导出 Notepad++ 期望的一些函数导入和调用。有一个使用 C# 的示例应用程序,但这仍然需要一个加载器 DLL,我从下面的评论/答案中假设这是 C# 的唯一方法。
最佳答案
非托管导出 => https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
DLLExport => https://github.com/3F/DllExport
How does it work?
Create a new classlibrary or proceed with an existing one. Then add the UnmanagedExports Nuget package.
This is pretty much all setup that is required.
Now you can write any kind of static method, decorate it with
[DllExport]
and use it from native code.
It works just like DllImport, so you can customize the marshalling of parameters/result withMarshalAsAttribute
.During compilation, my task will modify the IL to add the required exports...
关于c# - 是否可以像在 VS C++ 中一样从 C# DLL 导出函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4818850/