can't call C++ function from C#

2019-08-24 17:45发布

I have a DLL with a set of functions. The DLL was used with "themidia" to make it safe.

When I try to call the functions, C# spits out errors due to the functions names.

[DllImport("safety.dll", CallingConvention=CallingConvention.StdCall, ExactSpelling=true)]
private static extern IntPtr _encryptLogin@8(string string_0, string string_1);

If I remove the @8 and remove ExactSpelling=true, it just returns an exception saying no entry point.

What exactly am I doing wrong?

2条回答
SAY GOODBYE
2楼-- · 2019-08-24 18:06

Remove the "@", and in your attribute add EntryPoint="_encryptLogin@8"

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-24 18:18

As an alternative to specifying EntryPoint as rfmodulator suggested, you can use extern "C" in your C++ source, which will make the exported function names the same as their names in your C++ source.

C++ compiler normally mangles the names of functions, so that you can have overloaded functions (functions with the same name bu different parameters).

查看更多
登录 后发表回答