- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
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
! 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

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