Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Lahey Fortran calling CVF dll

jond
Novice
930 Views

Hi,

I am given the task of creating aFortran dll that will becalled from an application created in Lahey Fortran. All the source code that will go into creating the dll is written and tested under Compaq Visual Fortran over many years. Does anybody know if Lahey Fortran can call the dll created by CVF? I am hoping to avoid switching the compilers as this will probably open a huge can of worms.

Thanks for any help in advance,

Jon

0 Kudos
4 Replies
Steven_L_Intel1
Employee
930 Views
DLLs isolate compiler differences to a very large extent. As long as Lahey Fortran is able to specify the calling convention your Fortran code expexts, and you do not assume that the Fortran environments (I/O, allocatable variables, etc.) are common, you should be ok.
0 Kudos
joerg_kuthe
Novice
930 Views

Yes, you can call DLLs created by CVF or IVF.
However, since LF is restricted in the way DLL functions can be imported you might have to mangle the name and calling conventions on the CVF side. Here is anexample showing both the way the routine is imported in LF (using DLL_IMPORT).

qtXLSGetRowCount_LF.f90 (Lahey):

INTEGER
FUNCTION qtXLSGetRowCount( hDS, szTableName )
! Returns
! if >= 0: number of rows in a table
! if = -1: error
USE qtXLSDeclarations! defines KINDs, PARAMETERs etc.
INTEGER (qt_K_HANDLE), INTENT(IN) :: hDS
CHARACTER (qt_I_MaxTableNameLEN), INTENT(IN) :: szTableName
INTEGER, DLL_IMPORT :: qtXLSrc

qtXLSGetRowCount = qtXLSrc( VAL(hDS), szTableName )

RETURN
END FUNCTION

The header of the function (qtXLSrc) being imported from a DLL is shown here:

qtXLSGetRowCount_VF.f90 (CVF/IVF):

INTEGER

FUNCTION qtXLSGetRowCount( hDS, szTableName )
! hDS : handle to the datasource (EXCEL file)
! szTableName : a valid table name (can end with the character "$")
! Returns
! >= 0: number of rows in a table
! -1: error
!DEC$ ATTRIBUTES DLLEXPORT :: qtXLSGetRowCount
!DEC$ ATTRIBUTES ALIAS : '_qtXLSrc@8' :: qtXLSGetRowCount
!DEC$ ATTRIBUTES STDCALL :: qtXLSGetRowCount
!DEC$ ATTRIBUTES REFERENCE :: szTableName
... etc.

qtXLSGetRowCount is put in a DLL and exported as 'qtXLSrc'. In LF it is imported as shown before. Since qtXLSGetRowCount uses the WinAPI STDCALL convention, you have to tell LF. Compile using the -ml WINAPI option. E.g.:

lf95 -c-win -ml WINAPI qtXLSGetRowCount_LF.f90

Hope this helps.

Jrg Kuthe
QT software GmbH, Berlin, Germany
www.qtsoftware.de

0 Kudos
Jon_D
New Contributor II
930 Views

Thanks Jorg,

I have been having problems with the issue. I will give your suggestion a try. Based on your explanation, I can also export the routines from CVF using C calling convention and compile on the LF side using the -ml MSVC option, is this correct?

Jon

0 Kudos
joerg_kuthe
Novice
930 Views

Yes, to my understandance of calling conventions, this should work as well.
You have to make sure that both sides use the same calling convention.

Joerg

0 Kudos
Reply