View previous topic :: View next topic |
Author |
Message |
Astelix
Joined: 17 Dec 2008 Posts: 13
|
Posted: Fri Dec 19, 2008 3:45 pm Post subject: C# and FTN95 |
|
|
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.
 |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Fri Dec 19, 2008 5:36 pm Post subject: |
|
|
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". |
|
Back to top |
|
 |
Astelix
Joined: 17 Dec 2008 Posts: 13
|
Posted: Sat Dec 20, 2008 12:32 am Post subject: |
|
|
Thank you Paul, that helped. |
|
Back to top |
|
 |
|