无法在 DLL 中找到入口点
我有一个 C# 应用程序,我试图从中发送参数到 C++ 函数。但是,我收到错误(主题中提到)
C# application:
static class SegmentationFunctions
{
[DllImport("MyApplication.dll", EntryPoint = "fnmain", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int fnmain(string search);
}
}
public partial class MainWindow:Window
{
public MainWindow()
{
InitializeComponent();
string search = "test string here";
int scommand = SegmentationFunctions.fnmain(search);
}
C++ file.h
extern "C" QUERYSEGMENTATION_API int fnmain(char query[MAX_Q_LEN]);
C++ file .cpp
extern "C" QUERYSEGMENTATION_API int fnmain(char searchc[MAX_LEN_Q])
{
do something...
}
I have a C# application from which I am trying to send a parameter to a C++ function. However, I am getting the error (mentioned in the subject)
C# application:
static class SegmentationFunctions
{
[DllImport("MyApplication.dll", EntryPoint = "fnmain", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int fnmain(string search);
}
}
public partial class MainWindow:Window
{
public MainWindow()
{
InitializeComponent();
string search = "test string here";
int scommand = SegmentationFunctions.fnmain(search);
}
C++ file.h
extern "C" QUERYSEGMENTATION_API int fnmain(char query[MAX_Q_LEN]);
C++ file .cpp
extern "C" QUERYSEGMENTATION_API int fnmain(char searchc[MAX_LEN_Q])
{
do something...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dependency Walker 可以向您显示从 DLL 中有效导出的函数。您将能够看到您的
fnmain
是否存在,或者它是_fnmain
,或者其名称中有 C++ 修饰符。Dependency Walker can show you what functions are effectively exported from the DLL. You will be able to see if your
fnmain
is there at all, or it is_fnmain
instead , or has a C++ decoration in its name.请注意,默认情况下,Visual Studio 不会将本机输出复制到与托管输出相同的文件夹中。
手动将本机输出复制到托管构建文件夹并重试 - 如果这是您的问题,那么您需要更改 C++ 构建设置以将目标文件夹与托管应用程序文件夹相同。
您的代码是正确的 - 只要正确定义了 QUERYSEGMENTATION_API 宏,并且您的 dll 实际上构建为“MyApplication.dll”,
我就会从文件系统手动运行可执行文件 - 确保最新的 exe 和 dll 位于同一目录中文件夹,如果失败,请运行depends.exe 来解决这个问题。
Note that by default visual studio will not copy your native output to the same folder as your managed output.
manually copy native output to your managed build folder and try again - if that is your problem then you need to change the C++ build settings to put the destination folder the same as your managed app folder.
Your code is correct - so long as the QUERYSEGMENTATION_API macro is defined correctly and your dll is in fact built as "MyApplication.dll"
I would manually run the executable from the file system - making sure that the latest exe and dll are in the same folder, and if it fails run depends.exe to figure it out.