C#调用C ++ DLL得到EntryPointNotFoundException [英] C# call a C++ dll get EntryPointNotFoundException

查看:107
本文介绍了C#调用C ++ DLL得到EntryPointNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是gaven一个C ++ DLL文件, LIB 文件和一个头文件。我需要从我的C#应用​​程序调用它们。

I was gaven a C++ dll file, a lib file and a header file. I need to call them from my C# application.

头文件看起来是这样的:

header file looks like this:

class Clog ;

class EXPORT_MACRO NB_DPSM
{
private:
    string sFileNameToAnalyze ;

    Clog *pLog ;

    void write2log(string text) ;

public:
    NB_DPSM(void);
    ~NB_DPSM(void);

    void setFileNameToAnalyze(string FileNameToAnalyze) ;    
    int WriteGenbenchData(string& message) ;
};

在我的C#code,我有那些code:

In my C# code, I have those code:

internal ReturnStatus correctDataDLL(string rawDataFileName)
        {
            if (rawDataFileName == null || rawDataFileName.Length <= 0)
            {
                return ReturnStatus.Return_CannotFindFile;
            }
            else
            {
                setFileNameToAnalyze(rawDataFileName);                          
            }

            string msg = "";
            int returnVal = WriteGenbenchData(ref msg);


            return ReturnStatus.Return_Success;
        }

[DllImport("..\\..\\thirdParty\\cogs\\NB_DPSM.dll")]
public static extern void setFileNameToAnalyze(string fileName);


[DllImport("..\\..\\thirdParty\\cogs\\NB_DPSM.dll")]
public static extern int WriteGenbenchData(ref string message);

EntryPointNotFoundException setFileNameToAnalyze(rawDataFileName); 语句

几个问题:

  1. 我需要补充的是 LIB 文件到我的C#项目的地方?怎么样?

  1. do I need to add that lib file into somewhere of my C# project? how?

我需要的头文件添加到我的C#项目?怎么样? (无编译错误现在)

do I need to add the header file into my C# project? how? (no compile error for now)

我想删除这些.. \\ .. \\ \\第三方齿\\硬code路径。如何呢?

I would like to remove those "..\\..\\thirdParty\\cogs\\" hardcode path. how to this?

如何让乘坐的 EntryPointNotFoundException

感谢

推荐答案

您不必包含任何头文件或C#项目的lib文件。这些文件是没用的,你啦。

You don't need to include either the header file or the lib file in your C# project. These files are useless to you anyway.

您购买的EntryPointNotFound异常的原因是你对那些进入点提供不正确的名称。当你编译一个C ++项目,编译器中加入有关参数的其他信息和返回类型轧液的名称。 (您可以使用DUMPBIN.EXE实用看到这些入口点。)

The reason you are getting an EntryPointNotFound exception is that you've provided incorrect names for those entry points. When you compile a C++ project, the compiler mangles the names by adding additional information about parameters and return types. (You can use the dumpbin.exe utility to see these entry points.)

真正的问题,然而,就是你的DLL evidentally包含一个C ++类。 setFileNameToAnalyze和WriteGenbenchData是该类的实例方法,而不是静态函数。你不能叫他们不先创建NB_DPSM类的一个实例。

The real problem, however, is that your DLL evidentally contains a C++ class. "setFileNameToAnalyze" and "WriteGenbenchData" are instance methods of that class, not static functions. You can't call them without creating an instance of the NB_DPSM class first.

这也许可以仅使用P / Invoke来办,但在这一点上,我认为这是可能更多的麻烦比它的价值。您应该创建一个托管C ++类库来包装旧的DLL来代替。

It might be possible to do that using only P/Invoke, but at this point I think it's likely more trouble than it's worth. You should create a managed C++ class library to wrap the old DLL instead.

至于你的问题的一部分,(3),只是删除的路径,并确保NB_DPSM.dll驻留在同一bin目录作为输出文件的结果。

As to part (3) of your question, just remove the paths and make sure that NB_DPSM.dll resides in the same bin directory as the result of your output files.

这篇关于C#调用C ++ DLL得到EntryPointNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆