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 

Running Fortran DLL in Excel VB

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
fettouhi



Joined: 02 Sep 2010
Posts: 4

PostPosted: Thu Sep 23, 2010 10:06 am    Post subject: Running Fortran DLL in Excel VB Reply with quote

Hi, I'm trying to get a dll file I created with Silverfrost FTN95 implemented into Excel via VB. I have the following fortran subroutine

SUBROUTINE SRK (C,F,NV,NL,NS,T,P,improved,BETA_IN,LIST,NEQ,Z,SOLID,BETA,Y)

which is defined in FORTRAN this way

PARAMETER (NCMAX=15,NFMAX=15)

INTEGER :: NEQ,F,C
INTEGER :: improved
INTEGER :: LIST(NCMAX),NV,NL,NS,SOLID(NCMAX)

DOUBLE PRECISION :: P,T
DOUBLE PRECISION :: Y(NCMAX,NFMAX)
DOUBLE PRECISION :: BETA_IN(NFMAX)
DOUBLE PRECISION :: BETA(NFMAX) ,Z(NCMAX)

in VB I have defined it this way:

Declare Sub SRK Lib "H:\Programs\LUWS (SRK) dll\LUWS_SRK.dll" (ByRef C As Integer, _
ByRef F As Integer, ByRef NV As Integer, ByRef NL As Integer, _
ByRef NS As Integer, ByRef T As Double, ByRef P As Double, _
ByRef improved As Integer, ByRef Betain As Double, ByRef LIST As Integer, _
ByRef NEQ As Integer, ByRef Z As Double, ByRef _
SOLID As Integer, ByRef BETA As Double, ByRef Y As Double)

My big problem is now that when I run my VB script, it never enters the fortran dll. It crashes for some reason and I think it is because Y is a 15x15 matrix. How do you define those in VB?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Thu Sep 23, 2010 11:31 am    Post subject: Reply with quote

There are two issues here.

1. The VB arrays will probably be safe arrays with a header before the data that specifies the shape. Fortran arrays effectively have no header and the shape may be passed as an additional argument that is hidden in Fortran. I would have to check the details on this.

2. I think that VB will use the STDCALL protocol and this is not the FTN95 default. There is some information on this in the FTN95 help file and (I think) in the Forum Knowledge Base.
Back to top
View user's profile Send private message AIM Address
fettouhi



Joined: 02 Sep 2010
Posts: 4

PostPosted: Thu Sep 23, 2010 12:38 pm    Post subject: Reply with quote

Many thanks for the reply. I've already added F_STDCALL subroutine in FORTRAN in order to make it visible for VB. I additionally tested the resulting dll with dumpbin.exe to see if all subroutines were exported. I compile my dll file this way:

FTN95 SRK.f95 /IMPORT_LIB SOURCE.dll
slink SRK.OBJ SOURCE.dll -EXPORTALL -DLL /FILE:SRK.dll

This is what I have written in the header of the VB macro

Public Function srk(C As Integer, F As Integer, _
NV As Integer, NL As Integer, NS As Integer, T As Double, _
P As Double, improved As Integer, Bin As Range, LIST As Range, _
NEQ As Integer, Z As Range, SOLID As Range) As Variant

Dim Betain(1 To 15) As Double
Dim Listin(1 To 15) As Integer
Dim Zin(1 To 15) As Double
Dim Solidin(1 To 15) As Integer
Dim BETA(1 To 15) As Double
Dim Y(1 To 15, 1 To 15) As Double
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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