forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

calling a static c# method from f95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
j clark



Joined: 29 Mar 2008
Posts: 20
Location: Bala Cynwyd (Pennsylvania)

PostPosted: Mon Mar 31, 2008 11:09 pm    Post subject: calling a static c# method from f95 Reply with quote

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
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Tue Apr 01, 2008 8:04 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Tue Apr 01, 2008 10:00 am    Post subject: Reply with quote

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
View user's profile Send private message
j clark



Joined: 29 Mar 2008
Posts: 20
Location: Bala Cynwyd (Pennsylvania)

PostPosted: Tue Apr 01, 2008 11:10 am    Post subject: Calling a C# method from FTN95 Reply with quote

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
View user's profile Send private message AIM Address
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Tue Apr 01, 2008 12:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
j clark



Joined: 29 Mar 2008
Posts: 20
Location: Bala Cynwyd (Pennsylvania)

PostPosted: Tue Apr 01, 2008 12:56 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group