无法在 DLL 中找到入口点

发布于 2025-01-08 12:53:08 字数 814 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2025-01-15 12:53:08

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.

水波映月 2025-01-15 12:53:08

请注意,默认情况下,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文