我有这个 C 代码:
real_T addition(const struct_T parameters)
{
return parameters.a + parameters.b;
}
typedef struct
{
real_T a;
real_T b;
} struct_T;
typedef double real_T;
我像这样从 C# 调用它:
using System.Runtime.InteropServices;
namespace AdditionConsoleApplication
{
class Program
{
[DllImport(@"X:\Bla\Addition.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double addition(struct_T parameters);
static void Main(string[] args)
{
struct_T parameters = new struct_T();
parameters.a = 1;
parameters.b = 3;
Console.WriteLine(addition(parameters));
}
}
}
这里struct_T:
[StructLayout(LayoutKind.Sequential)]
class struct_T
{
public double a;
public double b;
}
不幸的是,数学不正确:
2.72645911468311E-284
有人能看出什么不对吗?