我的c ++函数如下所示,
# define MyFunction _declspec(dllexport)
extern "C" {
MyFunction int AddNumbers(int a, int b)
{
return a + b;
}
MyFunction int SubtractNumbers(int a, int b)
{
return a - b;
}
}
从Windows应用程序调用c ++函数如下
private void btnNumber_Click(object sender, EventArgs e)
{
GetNumber();
}
public const string cppFunctionsDll = @"..\..\..\Debug\CPP.dll";
[DllImport(cppFunctionsDll, CallingConvention = CallingConvention.Cdecl)]
public static extern int AddNumbers(int a, int b);
[DllImport(cppFunctionsDll, CallingConvention = CallingConvention.Cdecl)]
public static extern int SubtractNumbers(int a, int b);
public void GetNumber()
{
SubtractNumbers(1,2);
}
在Windows一侧执行代码时出错=>'无法加载DLL'...... \ Debug \ AccurynCPP.dll'或其依赖项之一:找不到指定的模块。(0x8007007E)'
我的cpp dll路径是> D:\ Project \ December \ 17-12-2020 \ Project_Name \ Debug
请尝试对绝对dll路径进行硬编码,或将其放入相应的调试bin文件夹中。
MSVC的将解决路径current directory
/ System folder: e.g. C:\windows\system32
/ $Path environment variable
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句