[英]Access C++ static methods from 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
在C ++中与在C#中的含义不同。 在命名空间范围内, static
给出了一个名称内部链接,这意味着它只能在包含该定义的翻译单元中访问。 没有静态,它具有外部链接,并且可以在任何翻译单元中访问。
如果要使用DllImport
则需要删除static
关键字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.