|
发表于 2020-5-7 09:30:02
|
显示全部楼层
我也有同样问题,我的C++ dll 头文件如下:
namespace MathFuncs
{
class MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);
// Returns a - b
static __declspec(dllexport) double Subtract(double a, double b);
// Returns a * b
static __declspec(dllexport) double Multiply(double a, double b);
// Returns a / b
// Throws DivideByZeroException if b is 0
static __declspec(dllexport) double Divide(double a, double b);
};
}
然后在C++里面可以调用,但在C#里面就遇到问题。
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyCSharpExecRefsDll
{
class Program
{
static void Main(string[] args)
{
myWin32 mywin32 = new myWin32();
Console.WriteLine(myWin32.Add(3, 4));
}
public class myWin32
{
[DllImport("MathFuncsDll1.dll")]
public static extern double Add(double a, double b);
[DllImport("MathFuncsDll1.dll")]
public static extern double Subtract(double a, double b);
[DllImport("MathFuncsDll1.dll")]
public static extern double Multiply(double a, double b);
[DllImport("MathFuncsDll1.dll")]
public static extern double Divide(double a, double b);
}
}
}
调用的时候总是说没有这个入口。
Unable to find entry point named "Add" in DLL "MathFuncDll1.dll" |
|