如何从C++DLL中的C#简单函数调用
How to call from C# simple function in C++ DLL
我在c++中有一个简单的函数(不是类的方法)
__declspec(dllexport) extern "C" void __stdcall TestFunc();
我试着从c#调用它:
[DllImport("ImportTest.dll")]
public static extern void TestFunc();
...
TestFunc();
它抛出一个"找不到入口点"异常。
怎么了?
谢谢你帮我:)
Try(猜测,DLL是在VS中编写的)
extern "C" __declspec(dllexport) void __stdcall TestFunc();
那就是:
__declspec(dllexport)
通知编译器,此函数将从DLL导出extern "C"
主要防止函数名称的修饰__stdcall
,因为如果在[DllImport]
指令中指定none,这是默认的调用约定
以后,您可以使用DLL导出查看器检查您的函数是否从DLL导出。
在C++函数中,在标头处(如果函数在标头中声明)添加
extern "C" _declspec(dllexport) void TestFunc();
在函数定义中使用
_declspec(dllexport) void TestFunc()
{
}
在C#端,您需要声明一个类似的函数
[DllImport(@"ImportTest.dll",
EntryPoint = "TestFunc",
ExactSpelling = false,
CallingConvention = CallingConvention.Cdecl)]
static extern void NewTestFunc()
现在使用,NewTestFunc()
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 关于简单C++函数(is_palindrome)的逻辑的问题
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 递归可变参数函数调用对简单 if.else 语句的性能
- 如何从C++DLL中的C#简单函数调用
- C++ VS2010编译器不使用"push"进行简单的函数调用
- 在 C++ 中将命令行参数作为函数调用的简单方法
- 类中简单的petsc函数调用