I want to import a FORTRAN DLL into Visual C #. Although I did this with functions, the problem arises when I want to import a subroutine with multiple outputs. Here is a simple example:
FORTRAN DLL:
Subroutine MySub(a,b,x,y)
Implicit None
Integer, INTENT(IN) :: a,b
Integer, INTENT(OUT) :: x,y
y=a+b
x=2*a+3*b
End Subroutine MySub
C # Console Application:
using System;
using System.Runtime.InteropServices;
namespace AlReTest
{
class Program
{
[DllImport(@"D:\...\AltRetTest.dll", CallingConvention=CallingConvention.StdCall)]
public static extern int MySub(int a, int b, [Out] int x, [Out] int y);
static void Main(string[] args)
{
int a = 4;
int b = 3;
int x = 0;
int y = 0;
MySub(a, b, x, y);
Console.WriteLine(x);
Console.WriteLine(y);
Console.WriteLine(MySub(a, b, x, y));
}
}
}
Here are the answers I get: x = 0, y = 0, MySub (a, b, x, y) = 17
I am a little new to Visual C # programming, but I think the above results mean two statements, i.e. "a + b" and "2 * a + 3 * b" were calculated but not assigned to x and y, and the last (2 * a + 3 * b) was assigned to the MySub function itself! I used OutAttributes in C #, also Intent [In], Intent [Out] in FORTRAN, but none of them changed the results. I would appreciate any help or advice.