Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
导入非托管dll时,C#和Delphi代码有不同的行为_C#_Delphi_Unmanaged_Dllexport_Math.net - Fatal编程技术网

导入非托管dll时,C#和Delphi代码有不同的行为

导入非托管dll时,C#和Delphi代码有不同的行为,c#,delphi,unmanaged,dllexport,math.net,C#,Delphi,Unmanaged,Dllexport,Math.net,我正在用C#中的Math.Net数值法求解稀疏线性方程组。 我正在尝试将此代码导出到dll(使用Robert Giesecke的非托管导出)并从Delphi代码运行它 这是我的C#代码: 而且效果很好 但当我试图在Delphi中导入此内容时: function create(n: integer): pointer; stdcall; external MathNetSolverLib; procedure addValue(row, col: Integer; value:double; p:

我正在用C#中的Math.Net数值法求解稀疏线性方程组。 我正在尝试将此代码导出到dll(使用Robert Giesecke的非托管导出)并从Delphi代码运行它

这是我的C#代码:

而且效果很好

但当我试图在Delphi中导入此内容时:

function create(n: integer): pointer; stdcall; external MathNetSolverLib;
procedure addValue(row, col: Integer; value:double; p:pointer); stdcall; external MathNetSolverLib;
procedure setRhs(row: Integer; value: double; p:pointer); stdcall; external MathNetSolverLib;
procedure solve(p: pointer); stdcall; external MathNetSolverLib;
function getSolutionByIndex(index: Integer; p:pointer): double; stdcall; external MathNetSolverLib;
TFQMR解算器返回错误的结果。TFQMR中的算法似乎有不同的行为

这很奇怪,因为当从C#或Delphi调用dll时,所有输入数据(变量A、b、n和输入点)都保持不变(我已经检查过了)


有人知道如何解释这一点吗?

很可能是浮点控制状态的差异造成的。还有一个事实是,您从Delphi传递一个指向函数的指针,但在C#端忽略它。这是你真正的密码吗?就个人而言,将稀疏解算器添加到Delphi程序中似乎是一种不雅观的方式。我推荐Tim Davis的稀疏解算器之一,用C编写。它很容易封装在DLL中,甚至可以直接编译到.obj和link。无论如何,我认为如果您需要详细的帮助,最好添加缺少的细节。我们无法知道A、b和n是否真的相同。您已经隐藏了设置它们的代码。您需要在问题的编辑中添加代码。我使用的稀疏解算器是Tim Davis的直接解算器之一。如Matlab所用。我高度赞扬他的解决者。参见:
 [DllImport("MathNetSolverLib.dll", EntryPoint = "create")]
        public static extern int create(int eqnumber);

        [DllImport("MathNetSolverLib.dll", EntryPoint = "addValue")]
        public static extern void addValue(int row, int col, double value, int ins);

        [DllImport("MathNetSolverLib.dll", EntryPoint = "setRhs")]
        public static extern void setRhs(int row, double value, int ins);

        [DllImport("MathNetSolverLib.dll", EntryPoint = "solve")]
        public static extern void solve(int ins);

        [DllImport("MathNetSolverLib.dll", EntryPoint = "getSolutionByIndex")]
        public static extern double getSolutionByIndex(int index, int ins);
function create(n: integer): pointer; stdcall; external MathNetSolverLib;
procedure addValue(row, col: Integer; value:double; p:pointer); stdcall; external MathNetSolverLib;
procedure setRhs(row: Integer; value: double; p:pointer); stdcall; external MathNetSolverLib;
procedure solve(p: pointer); stdcall; external MathNetSolverLib;
function getSolutionByIndex(index: Integer; p:pointer): double; stdcall; external MathNetSolverLib;