![](/img/trans.png)
[英]"Unable to find an entry point named [function] in dll" (c++ to c# type conversion)
[英]Unable to find an entry point named xxx in mixed C++ DLL and WPF C# project
我正在尝试将 C++ DLL 与 WPF ZD7EFA19FBE7D3972FD74ZZ 代码混合。 我的 DLL 称为 Transcoder.dll 并具有简单的界面:
转码器.h
#define MATHLIBRARY_API __declspec(dllexport)
namespace MathLibrary
{
class Functions
{
public:
// Returns a + b
static MATHLIBRARY_API double Add(double a, double b);
// Returns a * b
static MATHLIBRARY_API double Multiply(double a, double b);
// Returns a + (a * b)
static MATHLIBRARY_API double AddMultiply(double a, double b);
};
};
DLL 使用.def
文件(在Linker->Input->Module Definition File
中添加):
LIBRARY
EXPORTS
MathLibraryFunctionsAdd = ?Add@Functions@MathLibrary@@SANNN@Z
MathLibraryFunctionsAddMultiply = ?AddMultiply@Functions@MathLibrary@@SANNN@Z
MathLibraryFunctionsMultiply = ?Multiply@Functions@MathLibrary@@SANNN@Z
和我的简单 C# WPF class:
class MathLibrary
{
[DllImport("Transcoder.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MathLibraryFunctionsAdd", ExactSpelling = true, PreserveSig = true)]
static extern public double Add(double a, double b);
[DllImport("Transcoder.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MathLibraryFunctionsAddMultiply", ExactSpelling = true, PreserveSig = true)]
static extern public double AddMultiply(double a, double b);
[DllImport("Transcoder.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MathLibraryFunctionsMultiply", ExactSpelling = true, PreserveSig = true)]
static extern public double Multiply(double a, double b);
}
....
private async void Button_ClickAsync(object sender, RoutedEventArgs e) {
var result = MathLibrary.Add(2.0, 3.0);
Console.WriteLine(result);
}
一旦我调用MathLibrary.Add
function。 我得到:
System.EntryPointNotFoundException: 'Unable to find an entry point named 'MathLibraryFunctionsAdd' in DLL 'Transcoder.dll'.'
dumpbin.exe /exports.\Transcoder.dll 的 Output:
File Type: DLL
Section contains the following exports for Transcoder.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
3 number of functions
3 number of names
ordinal hint RVA name
1 0 0001110E MathLibraryFunctionsAdd = @ILT+265(?Add@Functions@MathLibrary@@SANNN@Z)
2 1 00011136 MathLibraryFunctionsAddMultiply = @ILT+305(?AddMultiply@Functions@MathLibrary@@SANNN@Z)
3 2 00011208 MathLibraryFunctionsMultiply = @ILT+515(?Multiply@Functions@MathLibrary@@SANNN@Z)
这里没有错误。 由于将 DLL 复制到应用程序目录中的错误构建步骤,它不起作用。 The question above can serve as a template for how to map a C++ DLL to a C# WPF application.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.