vb fortran dl not talkingl

vb fortran dl not talkingl

I am having trouble getting fortran talking to vb. I must be missing something. This runs then gets stuck in the fortran dll
VB won't let me put a(1,1) in the call statement
Anyone see what I am missing?
Thanks!
jhg
In VB
Option Explicit
Private Declare Sub ludcmp Lib "lu.dll" (array1() As Double, n1 As Integer, NP1 As Integer, indx1() As Integer)
ReDim a(1 To n, 1 To n) As Double
Call ludcmp(a(), n, NP, indx())

In Fortran
SUBROUTINE ludcmp(a,n,np,indx,d)
!DEC$ ATTRIBUTES DLLEXPORT :: ludcmp
!DEC$ ATTRIBUTES ALIAS:'ludcmp' :: ludcmp

10 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Jugoslav Dujic

For the start, my eyes see 5 arguments in definition but 4 in VB declaration. That could lead to stack corruption.

Also, I prefer having explicit ByRef for arguments in VB declaration; (I'm never sure what's the VB default, ByRef or ByVal). Try OPENing a file on the beginning of ludcmp and write all arguments received there.

Jugoslav

Jugoslav www.xeffort.com
Portrait de Community Admin

Maybe it is how you are passing arrays. When I pass arrays I would pass the first element in VB, but the parameter in Fortran would be an array. So in your declare:

Private Declare Sub ludcmp Lib "lu.dll"(array1 As Double, ...

ReDim a(1 to n, 1 to n) As Double

Call ludcmp(a(1, 1), ....

In Fortran:

Subroutine ludcmp(a,...

Real*8 :: a(n,n)

The ByRef is the default in VB, so you don't need that.

Thanks for your comments
I did have an error in the arguments, I think I have fixed it

in VB, I put this in a module

Declare Sub ludcmp Lib "c:JackVisualFortranLUlu.dll" (ByRef array1() As Double, ByRef n1 As Integer, ByRef NP1 As Integer, ByRef indx1() As Integer, ByRef p1 As Double)

In Fortran

SUBROUTINE ludcmp(a,n,np,indx,d)
!DEC$ ATTRIBUTES DLLEXPORT :: ludcmp
!DEC$ ATTRIBUTES ALIAS:'ludcmp' :: ludcmp

This has the same result it stops after the call to the fortran dll in VB

I did put a file into fortran to write to and the program didn't get that far.
Jhg

Portrait de Community Admin

In order to put a(1, 1) in the call statement, you need to take out the () in the Declare statement.

Per your suggestion, I changed the VB code to

Declare Sub ludcmp Lib "c:JackVisualFortranLUlu.dll" (array1 As Double, n1 As Integer, NP1 As Integer, indx1 As Integer, p1 As Double)

with a call to dll as

Call ludcmp(a(1, 1), n, NP, indx(1), p)

which is definite progress! At this point, it goes into the twilight zone and is lost
after the call to ludcmp. It doesn't create the file I set up in the fortran code to test

Do I need to do something more in fortran to tell which is data coming in and which is data going out of the dll?
Thanks much for your help!
JHG

Portrait de Community Admin

You shouldn't have to do anything on the Fortran side to say which parameters are coming in are being returned. You could add Intent(In) or Intent(Out), but as far as VB is concerned these are still passed by Reference. Example from my code:

Subroutine LetPayDef(lngPayDefsin,PayDescin,PayBasisin,PayYearin,PayMaxSalin, &
blnPayApply401a17in,iret)

!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS : 'LetPayDef' :: LetPayDef
!DEC$ ATTRIBUTES REFERENCE :: PayDescin,PayBasisin,PayYearin,PayMaxSalin

Use Dflib

include 'common.a'
include 'common.b'

Integer, Intent(In) :: lngPayDefsin
Character (Len=1), Intent(In) :: PayBasisin(lngPayDefsin),PayYearin(lngPayDefsin)
Character (Len=15), Intent(In) :: PayMaxSalin(lngPayDefsin)
Character (Len=40), Intent(In) :: PayDescin(lngPayDefsin)
Logical (2), Intent(In) :: blnPayApply401a17in(lngPayDefsin)
Integer, Intent(Out) :: iret

Can you set a breakpoint in the Fortran and hover over the parameters to see what their values are?

I have went back and made a simple prototype that has the properties
I was trying to get into the example. It works! I am still having trouble with
ludcmp (n and NP are not passing correctly into the dll) but I think I can figure it out from here. Thanks much for your excellent suggestions!
JHg

You should declare integer*4 As Long under VB to properly communicate with Fortran (or declare your integers as integer*2 under Fortran).

That was exactly the trouble I was having with ludcmp, n got passed correctly and NP, the next integer was goofy! By changing n NP to long in both the vb and the module definition, it works fine!
Thanks again for all of your great advice!!
jhg

Connectez-vous pour laisser un commentaire.