First, create a FORTRAN dynamic Connection Library Project and write a function to calculate the sum of the two numbers. The Code is as follows:
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
After realse compilation, copy the generated DLL.
Create a C # console project, paste the copied DLL to the DEBUG directory, and add the code.
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}
You need to add the namespace: system. runtime. interopservices;