主题:[讨论]C#调用Fortran写的DLL
用的是绑在VS.net上的Intel Fortran编译器
Fortran的代码
Subroutine xyADD(x,y)
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLEXPORT::xyADD
!DEC$ ATTRIBUTES ALIAS:'xyADD'::xyADD
integer x,y
integer sum
sum=x+y
return sum
End Subroutine
C#的代码
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("fdll1.dll",CallingConvention=CallingConvention.StdCall)]
public extern static int xyADD(ref int x,ref int y);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x, y, result;
x = int.Parse(textBox1.Text);
y = int.Parse(textBox2.Text);
result = xyADD(ref x, ref y);
textBox3.Text = result.ToString();
}
}
我想知道在Fortran里x、y和sum要怎么定义,用值传递还是地址传递?现在代码可以运行但结果不对,Fortran不会 是现学的,希望大家能给我指点指点
Fortran的代码
Subroutine xyADD(x,y)
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLEXPORT::xyADD
!DEC$ ATTRIBUTES ALIAS:'xyADD'::xyADD
integer x,y
integer sum
sum=x+y
return sum
End Subroutine
C#的代码
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("fdll1.dll",CallingConvention=CallingConvention.StdCall)]
public extern static int xyADD(ref int x,ref int y);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x, y, result;
x = int.Parse(textBox1.Text);
y = int.Parse(textBox2.Text);
result = xyADD(ref x, ref y);
textBox3.Text = result.ToString();
}
}
我想知道在Fortran里x、y和sum要怎么定义,用值传递还是地址传递?现在代码可以运行但结果不对,Fortran不会 是现学的,希望大家能给我指点指点