- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
I've inherited a Lahey Fortran DLL that I've compiled in DVF. A VB6 program calls it. The calling stream contains a double precision array, a long int array, and three 80-character strings. I've added the REFERENCE attribute to the DLL that allows me to set the length of the strings internally, without passing an integer length after the strings. The VB program is passing the strings ByVal.
The problem is that strings 1 & 2 make it to the DLL OK. String 3 is converted to meaningless junk. Does anyone know what's happening?
Thanks in advance,
Robin Olson
I've inherited a Lahey Fortran DLL that I've compiled in DVF. A VB6 program calls it. The calling stream contains a double precision array, a long int array, and three 80-character strings. I've added the REFERENCE attribute to the DLL that allows me to set the length of the strings internally, without passing an integer length after the strings. The VB program is passing the strings ByVal.
The problem is that strings 1 & 2 make it to the DLL OK. String 3 is converted to meaningless junk. Does anyone know what's happening?
Thanks in advance,
Robin Olson
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lahey and vf differ in the position of the string length argument in the call in vb. In vf the string length is the next argument after the string. In lahey the string length args are at the end of the arg list in the same order as the strings.
Thus for a fortran
subroutine a(str1,integ, str2)
the vf call is
call a(str1,len(str1),integ,str2,len(str2))
the lahey call is
call a(str1,integ,str2,len(str1),len(str2))
Thus for a fortran
subroutine a(str1,integ, str2)
the vf call is
call a(str1,len(str1),integ,str2,len(str2))
the lahey call is
call a(str1,integ,str2,len(str1),len(str2))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bill,
I suspected a difference between Lahey and DVF calling conventions. Thanks for the tip!
Regards,
Robin
I suspected a difference between Lahey and DVF calling conventions. Thanks for the tip!
Regards,
Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had not realised till I read your post and looked up 'Reference attribute', that I could pass strings with no length paramater.
I have since got it to work, but with differences from the two specifications I found in the help file. I found the following to work
!vba Excel 97
Declare Sub SgStateF Lib "FlowTranBwrs.dll" (ByVal Bwrsf As String, ByVal gNames As String, NdlGas As Long, GasMw As Double, ByVal BwrsTitle As String)
Sub BwrsStateCalc()
Dim Bwrsf As String * 2048
Dim gNames As String * 240
Dim NdlGas As Long
ReDim GasMw(1 To NdlGas) As Double
Dim BwrsTitle As String * 80
Call SgStateF(Bwrsf, gNames, NdlGas, GasMw(1), BwrsTitle)
End
!vf
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "SgStateF" :: SgStateF
!DEC$ ATTRIBUTES STDCALL ::SgStateF
!DEC$ ATTRIBUTES REFERENCE ::NLGAS,BWRSF,GNAMES,BWRSTITLE
SUBROUTINE SgStateF(BWRSF,GNAMES,NDLGAS,GASMW,BWRSTITLE)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
CHARACTER BWRSF*2048,GNAMES*240,BWRSTITLE*80
DIMENSION GASMW(NDLGAS)
END
The attributes are a combination of the two descriptions for passing strings to vb found in the vf help file ('Handling Data Types in Mixed-Language Programming/Handling Character Strings', and 'Fortran/Visual Basic Mixed-Language Programs/Calling Visual Fortran from Visual Basic' which are different! Also neither example shows a mix of string and other arguments. So if anyone is revising the help file...
I have since got it to work, but with differences from the two specifications I found in the help file. I found the following to work
!vba Excel 97
Declare Sub SgStateF Lib "FlowTranBwrs.dll" (ByVal Bwrsf As String, ByVal gNames As String, NdlGas As Long, GasMw As Double, ByVal BwrsTitle As String)
Sub BwrsStateCalc()
Dim Bwrsf As String * 2048
Dim gNames As String * 240
Dim NdlGas As Long
ReDim GasMw(1 To NdlGas) As Double
Dim BwrsTitle As String * 80
Call SgStateF(Bwrsf, gNames, NdlGas, GasMw(1), BwrsTitle)
End
!vf
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "SgStateF" :: SgStateF
!DEC$ ATTRIBUTES STDCALL ::SgStateF
!DEC$ ATTRIBUTES REFERENCE ::NLGAS,BWRSF,GNAMES,BWRSTITLE
SUBROUTINE SgStateF(BWRSF,GNAMES,NDLGAS,GASMW,BWRSTITLE)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
CHARACTER BWRSF*2048,GNAMES*240,BWRSTITLE*80
DIMENSION GASMW(NDLGAS)
END
The attributes are a combination of the two descriptions for passing strings to vb found in the vf help file ('Handling Data Types in Mixed-Language Programming/Handling Character Strings', and 'Fortran/Visual Basic Mixed-Language Programs/Calling Visual Fortran from Visual Basic' which are different! Also neither example shows a mix of string and other arguments. So if anyone is revising the help file...

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page