System.EntryNotFoundException:无法在 DLL 中找到入口点
我正在准备一个小型 C++ dll,其中的函数将从 C# 调用。
DLLTestFile.h
#ifdef DLLFUNCTIONEXPOSETEST_EXPORTS
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllexport)
#else
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllimport)
#endif
extern "C" DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b);
DLLTestfile.cpp
#include "stdafx.h"
#include "DLLFunctionExposeTest.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b)
{
return a + b;
}
C# 项目:
static class TestImport
{
[DllImport("DLLFunctionExposeTest.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fnSumofTwoDigits")]
public static extern int fnSumofTwoDigits(int a, int b);
}
public partial class MainWindow : Window
{
int e = 3, f = 4;
public MainWindow()
{
try
{
InitializeComponent();
int g = TestImport.fnSumofTwoDigits(e, f);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
我收到异常:“System.EntryNotFoundException:无法在 DLL 中找到入口点"
我使用的是 Visual Studio 提供的默认模板,在创建新项目时,Visual C++ -> Win32 项目 -> DLL(选中导出符号)。有人可以建议这个问题的解决方案吗?我找了很久也没找到问题所在。
I am preparing a small C++ dll in which the functions are to be called from C#.
DLLTestFile.h
#ifdef DLLFUNCTIONEXPOSETEST_EXPORTS
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllexport)
#else
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllimport)
#endif
extern "C" DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b);
DLLTestfile.cpp
#include "stdafx.h"
#include "DLLFunctionExposeTest.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b)
{
return a + b;
}
C# project:
static class TestImport
{
[DllImport("DLLFunctionExposeTest.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fnSumofTwoDigits")]
public static extern int fnSumofTwoDigits(int a, int b);
}
public partial class MainWindow : Window
{
int e = 3, f = 4;
public MainWindow()
{
try
{
InitializeComponent();
int g = TestImport.fnSumofTwoDigits(e, f);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
I am getting the exception: "System.EntryNotFoundException: Unable to find the entry point in the DLL"
I am using the default template given by Visual Studio, when creating a new project, Visual C++ -> Win32 Project -> DLL (Export symbols checked). Can somebody please suggest the solution for this. I haven't been able to find the problem even after looking for long.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说效果很好,完整的文件供参考:
dllmain.cpp:
DLL.h:
Program.cs(为简单起见,Win32控制台应用程序):
Works fine for me, complete files for reference:
dllmain.cpp:
DLL.h:
Program.cs (Win32 Console Application for simplicity):
您的 C# 进程可能以 64 位运行,而您的 DLL 可能以 32 位运行,反之亦然。当进程和 DLL 的位数不匹配时,我就遇到过这个问题。
It could be that your C# process is running as 64-bits and your DLL is 32-bits or vice versa. I have seen this problem when the bit-ness of the processes and DLLs don't match.
看来您没有定义 DLLFUNCTIONEXPOSETEST_EXPORTS 所以您使用了 import statements 。要进行测试,请使用 dumpbin /exports 查看从 dll 导出了哪些函数。
添加
It looks like you don't define DLLFUNCTIONEXPOSETEST_EXPORTS so you use the import declaration . To test use dumpbin /exports to see what functions are exported from the dll.
Add