10
静态方法说你有下面的C++代码:访问C++从C#
extern "C" {
void testA(int a, float b) {
}
static void testB(int a, float b){
}
}
我想用DllImport
访问这在我的C#项目:
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
关键字。你将不得不删除静态。你可能会混淆它与声明一个类成员函数,声明它静态做了一些非常不同的事情。 –