我遇到了错误 “无法在 DLL“example.dll”中找到名为“foo”的入口点。
我使用了 depends.exe 和 DUMPBIN.exe。函数就在那里,它的名字没有被破坏。
你能看出这有什么特别不对的地方吗?
这是C++代码。
//example.cpp
//Using Multibyte Char Set. (if that matters)
//Edit: I can not change this code.
extern "C" _declspec(dllexport) int foo(const char *name)
{
...
}
这是 C# 代码。
//importing.cs
public static class ImportClass
{
[DllImport("example.dll")]
public static extern int foo(string name)
}
我无法修改 C++,它是由禁止它的外部源提供的。 提前致谢。
最佳答案
您可能是此处Name Mangling
的受害者。
Wikipedia Name Mangling
首先使用dumpbin.exe
列出您的dll 导出的定义。
eg: `dumpbin.exe /EXPORTS example.dll`
验证导出函数的名称。
接下来像这样使用 DLL 导入:
[DllImport("example.dll", EntryPoint = @"TheNameFrom DumpBin goes here")]
您可能还想查找 CallingConvention
属性。
关于C# 无法在未损坏的 C++ 库上找到入口点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24419213/