Fortran 시작 - C#Fortran DLL 호출

2646 단어 fortran
먼저 Fortran 동적 연결 라이브러리 항목을 만들고 두 수의 합을 계산하는 함수를 작성한다. 코드는 다음과 같다.
1 function MySum(x,y)
2 implicit none
3 !DEC$ ATTRIBUTES DLLEXPORT :: MySum
4 !DEC$ ATTRIBUTES ALIAS:'MySum'::Mysum
5 integer x,y,MySum
6 MySum=x+y
7 end function
Realse 컴파일 후 생성된 DLL을 복제합니다.
이어서 방금 복사한 DLL을 DEBUG 디렉토리에 붙여 넣을 C# 콘솔 항목을 새로 만듭니다.그리고 코드를 추가합니다.
 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 }
네임스페이스 추가: System.Runtime.InteropServices;

좋은 웹페이지 즐겨찾기