希望这是一个无脑简单的问题,但这表明我缺乏 C++ 专业知识。我是一名 C# 程序员,过去我使用 P/Invoke 和其他人的 C++/C dll 进行了大量工作。然而,这次我决定自己编写一个包装器 C++ dll(非托管),然后从 C# 调用我的包装器 dll。
我立即遇到的问题是我无法定义可以通过 p/invoke 找到的 C++ 函数。我不知道它的语法是什么,但这是我到目前为止正在尝试的:
extern bool __cdecl TestFunc()
{
return true;
}
本来我只是有这个,但它也不起作用:
bool TestFunc()
{
return true;
}
然后在 C# 方面,我有:
public const string InterfaceLibrary = @"Plugins\TestDLL.dll";
[DllImport( InterfaceLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "TestFunc" ), SuppressUnmanagedCodeSecurity]
internal static extern bool TestFunc();
一切都会编译,但当我执行此 C# p/invoke 调用时,我收到 System.EntryPointNotFoundException: 无法在 DLL 'Plugins\TestDLL.dll' 中找到名为 'TestFunc' 的入口点。
当然,这在 C++ 端一定是非常简单的事情,我只是不知道其语法。
你会想要使用extern "C"
也__declspec(export)
,像这样:
extern "C" _declspec(dllexport) bool TestFunc()
{
return true;
}
有关完整详细信息,请参阅MSDN 关于编组类型.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)