Silverfrost Forums

Welcome to our forums

C# and FTN95

19 Dec 2008 2:45 #4114

Can you explain why this doesn't work?

DLL ft95test.dll:

subroutine greeter(num) integer(kind=3), intent(in) :: num assembly_interface (name='greeter') print *, 'Hello ', num end subroutine

subroutine greeter2(greetee) character(len=*), intent(in) :: greetee assembly_interface (name='greeter2') print *, 'Hello ', greetee end subroutine

(compiles without problems)

C# Program (Console application): (references the dll)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Salford.Fortran;

namespace TestFortran { class Program { static void Main(string[] args) {

        int number = 99;
        string programmer = 'Thomas';
        ft95test.GREETER(number);
        ft95test.GREETER2(programmer, programmer.Length);
        Console.ReadLine();
    }
}

}

Error 3 The best overloaded method match for 'ft95test.GREETER(int*)' has some invalid arguments D:\Visual Studio 2008\Projects\F95Projects\Ft95Test\TestFortran\Program.cs 17 13 TestFortran Error 4 Argument '1': cannot convert from 'int' to 'int*' D:\Visual Studio 2008\Projects\F95Projects\Ft95Test\TestFortran\Program.cs 17 30 TestFortran Error 5 The best overloaded method match for 'ft95test.GREETER2(Salford.Fortran.Character*, int)' has some invalid arguments D:\Visual Studio 2008\Projects\F95Projects\Ft95Test\TestFortran\Program.cs 18 13 TestFortran Error 6 Argument '1': cannot convert from 'string' to 'Salford.Fortran.Character*' D:\Visual Studio 2008\Projects\F95Projects\Ft95Test\TestFortran\Program.cs 18 31 TestFortran

If I'm not passing the Length argument, I get the message that there is no version of Greeter2 with only one argument.

Why does Fortran want pointers? I think the conversion is done through the Assembly_interface? If I try to pass arguments by reference it doesn't help.

😮

19 Dec 2008 4:36 #4115

I am a little rusty on this subject but I think that you should be using the lower case 'greeter' etc. in your C# code otherwise you will not get the expected binding. The upper case form requires you to pass a reference.

See the help file under 'Calling Fortran from other .NET languages'.

19 Dec 2008 11:32 #4118

Thank you Paul, that helped.

Please login to reply.