c# - 如何从 C++ DLL 中的 C# 简单函数调用

标签 c# c++ dllimport

我在 C++ 中有一个简单的函数(不是类的方法)

__declspec(dllexport) extern "C" void __stdcall TestFunc();  

我尝试从 C# 中调用它:

[DllImport("ImportTest.dll")]  
public static extern void TestFunc();  

...  

TestFunc();

它抛出一个“找不到入口点”的异常。

怎么了?

谢谢你帮助我:)

最佳答案

试试(猜测,那个DLL是用VS写的)

extern "C" __declspec(dllexport) void __stdcall TestFunc();

那是:

  • __declspec(dllexport) 通知编译器,该函数将从 DLL 中导出;
  • extern "C" 主要是防止function name decorations ;
  • __stdcall,因为如果您在 [DllImport] 指令中没有指定,这是默认调用约定。

将来,您可以使用 Dll export viewer 检查您的函数是否从 DLL 导出.

关于c# - 如何从 C++ DLL 中的 C# 简单函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21160662/

相关文章:

c# - EPPlus Excel 导出 - 每条记录的所有数据值都进入 A 列吗?

c# - UIAutomation - InvokePattern 仅在调试时有效 - 按钮未被识别为按钮

c++ - 在多级继承中,如果其父级已经实现了纯虚方法,孙级是否需要实现纯虚方法?

c++ - 阅读 Firefox 书签

c++ - std::map 实现在 linux 和 windows 之间不同

c# - DllImport - C 类型到 .NET 类型

dllimport 无法定位 dll,即使它在 PATH 中

c# - POST 上的模型为空

c++ - 将非托管 "QT"dll 导入 C# 给出 dllNotFoundException 但存在

c# - 如何创建包含 CRL 分发点的自签名证书