资源预览内容
第1页 / 共1页
亲,该文档总共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(Dll1.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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号