C # call C ++ dll get EntryPointNotFoundException

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

The header file is as follows:

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) ;
};

In my C # code, I have the 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);

I received EntryPointNotFoundExceptionthe instructions setFileNameToAnalyze(rawDataFileName);.

A few questions:

  • Do I need to add this file libto some of my C # project? as?

  • Do I need to add a header file to my C # project? as? (no compilation error yet)

  • I would like to remove this "..\\..\\thirdParty\\cogs\\"hardcode path . how to do it?

  • How to get to this EntryPointNotFoundException?

thank,

+3
source share
4 answers

, lib #. .

, EntryPointNotFound, , . ++, , . ( dumpbin.exe, .)

, , , DLL, , ++. "setFileNameToAnalyze" "WriteGenbenchData" - , . , NB_DPSM.

, , P/Invoke, , , . ++ DLL.

(3) , , NB_DPSM.dll bin, .

+2

( ) extern "C" { ... }.

#. ( [DllImport])

+2

dll ++ , dll 1

extern "C" int GenBenchData( const string &filename, string & message ){
  NB_DPSM builder;
  builder.setFileNameToAnalyze(filename);
  return builder.WriteGenbenchData( message );
}

# ,

[DllImport("shim.dll", CharSet = CharSet.Auto)]
static extern int GenBenchData([MarshalAs(UnmanagedType.LPStr)]string filename, StringBuilder message);
+2

. DLL ++, (, depend.exe, ). ++ , . ++, ++ DLL. C, ( : # 64 C/++ - 32 )

+1

Source: https://habr.com/ru/post/1750189/


All Articles