我创建了一个 C++ DLL,我将其导入 C# 应用程序以重用函数。C ++中的功能代码是static bool IsDisplayDeviceAttached(char *Arg1[])
当我在 C# 程序中使用如下 DllImport 时,
[DllImport("DllName", EntryPoint="?IsDisplayDeviceAttached@@YA_NQAPAD@Z", CallingConvention = CallingConvention.Cdecl)]
static extern bool IsDisplayDeviceAttached([MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] Display);
我仍然收到错误为 EntryPointNotFound 异常。我也ExactSpelling = true
与上面一起使用,但都导致错误。
1)任何人都可以指导代码还有什么问题吗?
2) 另外,为什么我们要给 _Cdecl 和 ExactSpelling 参数等(想知道我们为什么在 DllImport 中编写它们)