【发布时间】:2017-02-23 08:58:11
【问题描述】:
假设你有以下 C++ 代码:
extern "C" {
void testA(int a, float b) {
}
static void testB(int a, float b){
}
}
我想在我的 C# 项目中使用 DllImport 访问它:
class PlatformInvokeTest
{
[DllImport("test.so")]
public static extern void testA(int a, float b);
[DllImport("test.so")]
internal static extern void testB(int a, float b);
public static void Main()
{
testA(0, 1.0f);
testB(0, 1.0f);
}
}
这对testA 非常有效,但testB 无法抛出EntryPointNotFoundException。
我可以从我的 C# 代码访问testB 吗?怎么样?
【问题讨论】:
-
在全局范围内声明为 static 的函数没有外部链接,因此永远无法导出。你必须去除静电。您可能会将其与声明类成员函数混淆,将其声明为静态会做一些非常不同的事情。
标签: c# c++ dllimport entrypointnotfoundexcept