1、C#调用Fortran DLL首先建立一个Fortran动态连接库项目,并写一个计算两数之和的函数,代码如下1 function MySum(x,y)2 implicit none3 !DEC$ ATTRIBUTES DLLEXPORT : MySum4 !DEC$ ATTRIBUTES ALIAS:MySum:Mysum5 integer x,y,MySum6 MySum=x+y7 end functionRealse编译后,复制生成的DLL.接着新建一个C#控制台项目,将刚才复制的DLL粘贴到DEBUG目录下.然后添加代码 1 class Program 2 3 DllImport(Dll
2、1.dll, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall) 4 public static extern int MySum(ref int x,ref int y); 5 static void Main(string args) 6 7 int x = 3; 8 int y = 4; 9 int result = MySum(ref x, ref y);10 Console.WriteLine(result);11 Console.ReadKey();12 13