“Unable to find an entry point named [function] in dll” (c++ to c# type conversion)

你。 提交于 2019-11-28 19:23:03
i_am_jorf

First make sure the function is actually exported:

In the Visual Studio Command Prompt, use dumpbin /exports whatever.dll

paxdiablo

C# doesn't support C++ name mangling and you either need to declare the C++ functions with

extern "C" {...}

(may not an option if they're from a third party), or call the mangled name directly if you can get it to work. It may be easier to get the third party to provide a non-mangled interface to the functionality.

Solved - at least to the point where the program does not break and actually returns me a bool value.

The key, I guess, was to specify the entry point as the 'mangled' name

    [DllImport(@"cnOCRsdk.dll", EntryPoint="?recoCHN_P_Name@CcnOCRsdk@@QAE_NPADPAURECO_DATA@@@Z")]
    public static extern bool recoCHN_P_Name(ref string imgPath, ref RECO_DATA o_data);

After that I got some other errors but the 'unable to find entry point' went away.

I'd write a wrapper using C++/CLI. This wrapper will be able to include the .h files and link to the .lib files you got from the third party vendor. Then it is both easy and safe to write a managed interface for your C# program.

I solved the same problem in these steps:

step 1) If you program your custom DLL in C++ using Visual studio,then at the property page of your project set the Common Language Runtime Support (/clr)parameter to Common Language Runtime Support (/clr).

step 2) To function deceleration in .h file use __declspec(dllexport) keyword like below:

__declspec(dllexport) double Sum(int a,int b);

step 3) Build and export DLL file, then use the Dependency Walker software to get your function EntryPoint.

step4) Import DLL file In the C# project and set EntryPoint and CallingConvention variable like below:

[DllImport("custom.dll", EntryPoint = "?Sum@@YAXHHHHHHNNN@Z", CallingConvention = CallingConvention.Cdecl)]

    public static extern double Sum(int a,int b);

You could try using the unmangled name while specifying a CallingConvention in the DllImport

Correct EntryPoint string could be found in ".lib" file that comes along with main unmanaged dll.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!