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

call dll from CVF

orangecccc
Beginner
636 Views
I've got a EXCEL/VBcode and dll (I know there are three subroutines within the dll) with input data files. So I'd like to convert this VB into Fortran code as a subroutine for linking with another big fortran code. My question is as follows:
1. What is a command line to call dll in fortran? (ex.!DEC$ ATTRIBUTES DLLIMPORT ...) Do I have to put a dll name or subroutine name?
2. I have two input data (one is a EXCEL spreadsheet, and the other ASCII file). So I can change the EXCEL spreadsheet toa input file. But how can Iopen/load the other ASCII file into the dll?
Thanks in advance....
FYI, the following is the part of the EXCEL/VB code:
Option Explicit
Private Declare Sub DefineProblem300 Lib "C:projectslm ecentch3ddlll.dll" _
(FName As String, ErrorCode As Integer, ErrorMsg As String)
Private Declare Sub RunCHESS Lib "C:projectslm ecentch3ddlll.dll" _
(ErrorCode As Integer, ErrorMsg As String, WaterVol As Single, ParticleMass As Single, Totals() As Double, Species() As Double)
Private Declare Sub SpeciesList Lib "C:projectslm ecentch3ddlll.dll" _
(ErrorCode As Integer, ErrorMsg As String, NC As Integer, NS As Integer, SpeciesNames() As String)
....
strDir = "C:projectslm ecentch3ddllcu.dat"
Call DefineProblem300(strDir, ErrorCode, ErrorMsg)
If ErrorCode > 0 Then
MsgBox ErrorMsg, vbCritical
Exit Sub
End If
...

Message Edited by orangecccc on 03-29-200610:31 AM

Message Edited by orangecccc on 04-05-200604:13 PM

0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
636 Views
1. What is a command line to call dll in fortran? (ex. !DEC$ ATTRIBUTES DLLIMPORT ...) Do I have to put a dll name or subroutine name?

Terminology correction: "command line" is the stuff you type in Command prompt or Start/run to invoke a program. More appropriate word would be e.g "syntax".

Now, reply: you don't have to do anything special to call a routine in a Dll -- you can just CALL it. !DEC$ ATTRIBUTES DLLIMPORT is optional, and it will work without it as well; what goes in there is subroutine name. However, you do have to *link* the .exe with .lib file, produced when you build the .dll.

2. I have two input data (one is a EXCEL spreadsheet, and the other ASCII file). So I can change the EXCEL spreadsheet to a input file. But how can I open/load the other ASCII file into the dll?

Does it mean that you plan to convert the Excel spreadsheet into an ASCII file?

But I don't get the question in any case -- you read a file by OPEN-ing it and READ-ing it, be it from the .exe or from the .dll. You can read it in .exe and pass its data to the .dll through argument-list, or only pass the filename to the .dll. In general, dll is not a world of its own -- it functions pretty much as normal set of routines in many aspects.
0 Kudos
orangecccc
Beginner
636 Views

Jugoslav

Thank you for your help.

The dll was generated from another person, not me. He gave me the EXCEL file with VB codeand input data.

I alreadyconverted the EXCEL spreedsheet into an ASCII file.

How can Iload the input data intothe dll and calculate the dll using the input data? I'musing CVF 6.6. I reviewed some examples for dll in CVF manual, but there was no example to handle input data file.

Message Edited by orangecccc on 03-30-200609:28 AM

0 Kudos
anthonyrichards
New Contributor III
636 Views

For informstion about using a FORTRAN DLL fronm Excel, try this link
and links therein http://softwareforums.intel.com/ids/board/message?board.id=5&message.id=17666

0 Kudos
Jugoslav_Dujic
Valued Contributor II
636 Views
You mean, you don't have the source code for the dll? If you have the dllname.lib file and know the routine prototypes, you can still call it from the Fortran .exe by linking it with the lib. If you don't have the .lib, you can try to generate one with makilib.exe or use dynamic binding with LoadLibrary/GetProcAddress (plenty of examples in this Forum).

Still, how did the input data get into the dll in the original VB/Excel code? Normally, I'd expect that VBA processed the spreadsheet and sent the data to the Fortran as array(s). Is that the case?
0 Kudos
Reply