【问题标题】:Unable to find entry point in DLL无法在 DLL 中找到入口点
【发布时间】:2012-02-22 10:03:04
【问题描述】:

我有一个 C# 应用程序,我试图从它向 C++ 函数发送一个参数。但是,我收到了错误(主题中提到)

C# 应用程序:

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++ 文件.h

extern "C" QUERYSEGMENTATION_API int fnmain(char query[MAX_Q_LEN]);

C++ 文件 .cpp

extern "C" QUERYSEGMENTATION_API int fnmain(char searchc[MAX_LEN_Q])
{

do something...

}

【问题讨论】:

  • QUERYSEGMENTATION_API 明确在您的 C++ 项目中定义为 __declspec(dllexport),当您在 Dependency Walker 中打开 MyApplication.dll 时,您能否看到导出的函数(depends.exe 是Visual Studio 工具,以防您不确定)?

标签: c# c++ visual-c++


【解决方案1】:

Dependency Walker 可以显示从 DLL 中有效导出的函数。您将能够看到您的 fnmain 是否存在,或者它是 _fnmain ,或者名称中有 C++ 装饰。

【讨论】:

    【解决方案2】:

    请注意,默认情况下,Visual Studio 不会将您的本机输出复制到与托管输出相同的文件夹中。

    手动将本机输出复制到托管构建文件夹并重试 - 如果这是您的问题,那么您需要更改 C++ 构建设置以将目标文件夹与托管应用文件夹相同。

    您的代码是正确的 - 只要正确定义了 QUERYSEGMENTATION_API 宏并且您的 dll 实际上构建为“MyApplication.dll”

    我会从文件系统手动运行可执行文件 - 确保最新的 exe 和 dll 在同一个文件夹中,如果失败,请运行 depends.exe 来解决。

    【讨论】:

    • 我已经有了在 C# 项目中获取最新 dll 的后期构建集。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 2021-08-05
    • 2017-08-31
    • 1970-01-01
    • 2015-09-28
    相关资源
    最近更新 更多