View previous topic :: View next topic |
Author |
Message |
j clark
Joined: 29 Mar 2008 Posts: 20 Location: Bala Cynwyd (Pennsylvania)
|
Posted: Mon Mar 31, 2008 11:09 pm Post subject: calling a static c# method from f95 |
|
|
How do you call a static C# method FROM Fortran in Visual Studio 2005?
I have tried various combinations of <namespace>.<class>.<method> in the ASSEMBLY_EXTERNAL statement and all fail with a compiler error: "Method Not Found...". The compiler apparently recognizes the .dll in the LIBRARY statement. Help. Please. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7926 Location: Salford, UK
|
Posted: Tue Apr 01, 2008 8:04 am Post subject: |
|
|
You will find instructions in the FTN95 help file under "Calling .NET methods from Fortran".
The class names etc are case-sensitive and the intelisense works OK so you can build up the name from the dropdown lists that automatically appear. |
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Tue Apr 01, 2008 10:00 am Post subject: |
|
|
Static methods are the simplest to call, in that you dont have to instantiate an object first. For a simple static method called PrintMe, in a class called Class1 in a namespace called StaticMethods, the Fortran should look like:
Code: | ASSEMBLY_EXTERNAL("StaticMethods.Class1.PrintMe") :: PRINTME
CALL PRINTME()
PAUSE
END |
|
|
Back to top |
|
|
j clark
Joined: 29 Mar 2008 Posts: 20 Location: Bala Cynwyd (Pennsylvania)
|
Posted: Tue Apr 01, 2008 11:10 am Post subject: Calling a C# method from FTN95 |
|
|
Thanks, gentlemen, but here is the exact, relevant code that
dosen't compile:
C#, built as a class library, VMSLink.dll:
namespace VMSLinkGroup {
public class VMSLink {
...
public static int RA_Connect(string ipaddr, out string result) {
...
and the FTN95 main program:
PROGRAM MAIN
...
LIBRARY "VMSLink.dll"
ASSEMBLY_EXTERNAL(NAME="VMSLink.RA_Connect") :: RA_CONNECT
...
STRING IPADDR, ERRMSG
...
IOSTAT = RA_CONNECT(IPADDR, ERRMSG)
...
The exact Error message is: "error 1117 The .NET Method
VMSLink.RAConnect was not found. Have you forgotton..."
What am I doing wrong? |
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Tue Apr 01, 2008 12:11 pm Post subject: |
|
|
The code below is the correct usage of your class.
Code: | ASSEMBLY_EXTERNAL("VMSLinkGroup.VMSLink.RA_Connect") :: RA_CONNECT
STRING IPADDR, ERRMSG
INTEGER IOSTAT
IOSTAT = RA_CONNECT(IPADDR, ERRMSG)
PRINT *, IOSTAT
PAUSE
END |
You should specify the library to compile/link with on the command line, like:
FTN95.EXE File.f95 /CLR /CLR_VER 2 /REF VMSLink.dll /BINARY out.dbk
and
DBK_LINK2.EXE /REF:VMSLink.dll file.exe out.dbk
Note I have used /CLR_VER 2 and DBK_LINK2 for use with .NET version 2.0, but the same would work for 1.1 (without /CLR_VER 2 and with DBK_LINK) |
|
Back to top |
|
|
j clark
Joined: 29 Mar 2008 Posts: 20 Location: Bala Cynwyd (Pennsylvania)
|
Posted: Tue Apr 01, 2008 12:56 pm Post subject: |
|
|
Thank you Andrew.
The "trick" is, apparently, simply to prefix the class with the namespace. The documentation could be just a tad more clear on that point. Thanks again. |
|
Back to top |
|
|
|