c# - 是否可以像在 VS C++ 中一样从 C# DLL 导出函数?

标签 c# c++ notepad++ dllexport

在 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 with MarshalAsAttribute.

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/

相关文章:

c# - 使用 Json.NET 序列化 : how to require a property not being null?

c++ - posix timer_create() 函数在 linux 上导致内存泄漏

notepad++ - Notepad++ 的项目文件?

c# - 如何在 INSERT 上将 BLOB 流式传输到 VARBINARY(MAX)

c# - 一个按钮执行两个命令

c++ - 规范化约束时,需要表达式是原子吗?

c++ - constructor\destructor 或者对OOP的理解

正则表达式将 href 链接更改为小写

ruby - Notepad++ 中的 Haml/Sass 语法突出显示?

c# - Moq - 如何在循环中调用具有不同参数的相同设置