用 C++ 编写的 C# DllImport 库

Max*_*oed 0 c# dll dllimport

我对 C# 很陌生。我自己用 C++ 编写了 Dll,我将在 C# 应用程序中使用该 dll 中的函数。

因此,我在 C++ 项目中声明函数时执行以下操作:

public static __declspec(dllexport) int captureCamera(int& captureId);
Run Code Online (Sandbox Code Playgroud)

然后我试图在 C# 应用程序中导入这个方法:

[DllImport("MyLib.dll")]
public static extern int captureCamera(ref int captureId);
Run Code Online (Sandbox Code Playgroud)

但我有一个例外:

Unable to find an entry point named 'captureCamera' in DLL 'MyLib.dll'.
Run Code Online (Sandbox Code Playgroud)

任务是在不指定 EntryPoint 参数的情况下执行 dllimport。有人可以帮助我吗?

not*_*row 5

public static __declspec(dllexport) int captureCamera(int& captureId);

是那种方法?如果是函数,就不能是静态的,因为staticdllexport是互斥的。

而且这个名字是乱七八糟的。请参阅http://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B_Name_Mangling。如果您可以获得损坏的名称,然后提供DllImport它 ( EntryPoint=MANGLED_NAME),它应该可以工作。

您可以为链接器提供.def包含导出函数定义的文件,并且它们的名称不会被修改:

项目.def:

EXPORTS
    captureCamera @1
Run Code Online (Sandbox Code Playgroud)