C#DLLImport for C++ dll

ray*_*ran 4 c# c++ dll managed dllimport

我有一个.dll内置的C++/CLI和.NET.因此,它的目标是.NET应用程序.API是一组使用托管类型的包装器,因此它是.NET本机的.我导入了.dll并添加了一个函数:

[DllImport(@"maplib.dll")]
public static extern bool initialize(string a);
Run Code Online (Sandbox Code Playgroud)

当我在我的C#代码中调用此函数时,它工作正常,但如果我想添加另一个函数,如...

[DllImport(@"maplib.dll")]
public static extern bool initialize(string a);
public static extern bool runfile(string a, string b);
Run Code Online (Sandbox Code Playgroud)

我运行程序时遇到此错误.它与第二个功能有关:

"无法从程序集'myapp,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'加载类型'myapp.main',因为方法'runfile'没有实现(没有RVA)."

为什么会出现此错误,如何解决?

小智 15

DllImport如果需要两个函数,则必须添加两次属性:

[DllImport(@"maplib.dll")]
public static extern bool initialize(string a);
[DllImport(@"maplib.dll")]
public static extern bool runfile(string a, string b);
Run Code Online (Sandbox Code Playgroud)

但是,如果您的dll是.NET,那么为什么不只是添加一个常规引用​​并使用它就像使用C#代码一样?