希望这是一个简单粗暴的问题,但这表明我缺乏 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: Unable to find an entry point named 'TestFunc' in DLL 'Plugins\TestDLL.dll'。
当然,这在 C++ 端一定是非常简单的东西,我只是不知道它的语法。