Calling Fortran-DLLs with Visual Basic 4.0 
Author Message
 Calling Fortran-DLLs with Visual Basic 4.0

Hello there,

I want to call a DLL written in fortran 90 with Fortran Powerstation
4.0 with Visual Basic 4.0.

I have tried several Examples from the Online Manual, but Visual Basic
always says, it can not find the specified DLL-Function (Run-Time
Error 453 - Specified DLL not found).

Can somebody offer any explanation or give (simple) example
of how it is done right ?

Thank you in advance,

Axel Moschuering




Fri, 17 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Quote:

>.....
>Can somebody offer any explanation or give (simple) example
>of how it is done right ?

I second the need. I put my DLL into my VB project and declared the
DLL using:

Private Declare Sub Lib "Pet2pt" (ByVal arr as Array)

with every permutation I could think of to make the error:

        "User-defined type not defined"

go away.... but it won't. What to do?



Sat, 18 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0



Quote:
> Hello there,

> I want to call a DLL written in Fortran 90 with Fortran Powerstation
> 4.0 with Visual Basic 4.0.

> I have tried several Examples from the Online Manual, but Visual Basic
> always says, it can not find the specified DLL-Function (Run-Time
> Error 453 - Specified DLL not found).

> Can somebody offer any explanation or give (simple) example
> of how it is done right ?

> Thank you in advance,

> Axel Moschuering

I've had the same trouble using VB4 and FPS 4.0.  However, if you run
Fortran Power
Station, it will start your VB app and you can set breakpoints and debug in
Fortran.

I've inherited some legacy code that makes 1 call to the Fortran DLL, but
it has 48
arguments!  I had a lot of trouble passing the arguments, especially arrays
of strings.     The manual is no help whatsoever in doing that -- I finally had
to call Microsoft and they pointed me to a file on their website that had
the answers that I needed.
--
Richard Gardner    SW Engineer
Eastman Kodak     Rochester, NY



Sat, 18 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Quote:

>.....
>Can somebody offer any explanation or give (simple) example
>of how it is done right ?
>....

Try this:

http://www.microsoft.com/kb/articles/q161/8/25.htm

Microsoft Knowledge Base

SAMPLE: How Visual Basic 4.0 Calls C and Fortran
  DLLs

Last reviewed:
  February 5, 1997
  Article ID:
  Q161825

And especially the sample contained in:

http://www.microsoft.com/kb/softlib/mslfiles/Vbstring.exe

Here is a hint: I don't think the "f77" portion of FPS4 is working
when it comes to DLLs. Be sure you put the "f90" extension on your
samples and examples. Re-make your FPS projects and include the "f90"
files. It can be exactly the same code in the files, but the "f90"
extension makes all the difference. Compile and link is different.
What is produced is a copy of a DLL which CAN be called from VB. After
much heartache, I fianlly got the following to work (at least it runs
without the 48 and 453 errors.... I still have a problem with the
value that is passed and returned.... but at least this is a major
step in the right direction):

1) a fortran file named pet2pt.f90:

      SUBROUTINE pet2pt(arr1)
!MS$ATTRIBUTES DLLEXPORT,STDCALL:: pet2pt
        REAL  arr1
        arr1=123.0
      END SUBROUTINE
2) a VB form with this in the GENERAL/declarations section (I was
using some example snip code to be sure exactly where was the DLL file
I was trying to access):

Option Explicit

Private Const OF_EXIST = &H4000
Private Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
    cBytes As Byte
    fFixedDisk As Byte
    nErrCode As Integer
    Reserved1 As Integer
    Reserved2 As Integer
    szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As
String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long

Private Declare Sub pet2pt Lib _
"C:\Pwrlg32b\Working\UserProgPet2pt\Pet2pt\pet2pt.dll" Alias _

3) Put the following in the FORM/load section of the VB form:

Private Sub Form_Load()
Dim msg As String, Title As String, Help As String
Dim Style As Integer, Ctxt As Integer, Response As Integer

Static any_arr1 As Single

      ' this is to find out what DLLs are available
      Dim foundFortranDLL As Long
      Dim ofs As OFSTRUCT
      Dim newline As String
    foundFortranDLL = OpenFile(App.Path & "\pet2pt.dll", ofs, _
OF_EXIST)
    ' 1 file found, -1 file not found
    ' Adjust to boolean values for convenience
    If (foundFortranDLL = -1) Then foundFortranDLL = False Else
foundFortranDLL = True
    If (Not foundFortranDLL) Then
        msg = "Unable to find Fortran DLL in " & App.Path & _
"\pet2pt.dll"
        MsgBox msg
        End  ' cannot go any furthur
    Else
        msg = "DLL location= " & App.Path & "\pet2pt.dll"
        MsgBox msg
    End If

Call pet2pt(any_arr1)

msg = "array=" & any_arr1   ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Pet2pt Demonstration"  ' Define title.
Help = "DEMO.HLP"   ' Define Help file.
Ctxt = 1000 ' Define topic
            ' context.
            ' Display message.
Response = MsgBox(msg, Style, Title, Help, Ctxt)

End Sub

The example in VBSTRING.EXE will show how to do it for strings.

Jeffrey L. Baldwin
Mind & Vision Computer Systems
"Intelligent Processing Systems for the Energy Industry"
Voice/Fax/Data: (281) 550-4534     (800) MVCSTLM

http://idt.net/~mvcs



Sun, 19 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Quote:

>...I've had the same trouble using VB4 and FPS 4.0.  However, if you run
>Fortran Power
>Station, it will start your VB app

How is this done? I have a FPS4 DLL that is exported to the VB4 front
end calling argument. How do you start the VB4 front end from FPS4?

Quote:
> and you can set breakpoints and debug in
>Fortran.

>I've inherited some legacy code that makes 1 call to the Fortran DLL, but
>it has 48 arguments!

Can you post or send me the Fortran declaration and export code snip,
plus the corresponding VB declaration and calling protocol? I've got
the same problem, except I have to handle 230 or so arrays,
parameters, etc. Also, I have over 2300 elements and "things" packed
in a common block that need to be passed in another application. Have
you seen how to pass common blocks in and out of DLLs?

Quote:
> I had a lot of trouble passing the arguments, especially arrays
>of strings. The manual is no help whatsoever in doing that -- I finally had
>to call Microsoft

Was this the $95/incident deal? What number did you call?

Quote:
> and they pointed me to a file on their website that had
>the answers that I needed.

What file was that? What is the address? I found Q181625 by poking
around in their knowledge base. Is that the same file?

Jeffrey L. Baldwin
Mind & Vision Computer Systems
"Intelligent Processing Systems for the Energy Industry"
Voice/Fax/Data: (281) 550-4534     (800) MVCSTLM

http://idt.net/~mvcs



Sun, 19 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Quote:

> =
> Hello there,
> =
> I want to call a DLL written in Fortran 90 with Fortran Powerstation
> 4.0 with Visual Basic 4.0.
> =
> I have tried several Examples from the Online Manual, but Visual Basic
> always says, it can not find the specified DLL-Function (Run-Time
> Error 453 - Specified DLL not found).
> =
> Can somebody offer any explanation or give (simple) example
> of how it is done right ?

I have a (simple) solution to some of your problems.

Example Fortran code

SUBROUTINE MYSUB(M,N,MATRIX,NAME)
!MS$ATTRIBUTES DLLEXPORT, STDCALL :: MYSUB
!MS$ATTRIBUTES REFERENCE :: M
!MS$ATTRIBUTES REFERENCE :: N
!MS$ATTRIBUTES REFERENCE :: MATRIX
!MS$ATTRIBUTES REFERENCE :: NAME
!
INTEGER :: M, N
REAL(8), DIMENSION(M,N) :: MATRIX
CHARACTER(80) :: NAME
!
INTEGER :: I, J
!
DO I=3D1,M
        DO J=3D1,N
                MATRIX(M,N)=3DI*J
        END DO
END DO
!
NAME=3D'Detta =E4r en str=E4ng'
!
RETURN
!
END SUBROUTINE MYSUB

Compile the code to an DLL. Use the command DUMPBIN /EXPORTS xxxx.DLL
this will give the following result:

         Section contains the following Exports for VATAN2.dll

                   0 characteristics
            334E18BD time date stamp Fri Apr 11 12:55:57 1997
                0.00 version
                   1 ordinal base
                   2 number of functions
                   2 number of names

            ordinal hint   name


In Visual Basic you then declare the subroutine like this:

Type strings
    content As String * 80
End Type


Byref N as integer, Byref MATRIX as double ,NAME as strings)

This should work

Many regards Jonas Lindemann



Sun, 19 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Simple, VB dont support Array as a declare type of element.

define a structure (Type) as a array then dim the parameter with that type.

Type sStringArray
        sString() as string
end type

... or something like that!



Tue, 21 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0



Quote:

> >...I've had the same trouble using VB4 and FPS 4.0.  However, if you run
> >Fortran Power
> >Station, it will start your VB app

> How is this done? I have a FPS4 DLL that is exported to the VB4 front
> end calling argument. How do you start the VB4 front end from FPS4?

You can do this by doing the following:
In FPS goto Build/Settings menu select the Debug tab.
For general settings category
in the Executable for debugging enter the fullpath and VB32.EXE like
C:\PROGRA~1\MICROS~1\VB32.EXE
For program arguments enter the fullpath and vb project like
C:\PROJECT\PROJECT1.VBP
Then select Additional DLL's category
browse and select the compiled FORTRAN dll

You can now set breakpoints in your dll.
Select BUILD/Debug and run
This will start VB with your project.  Make sure that the DLL references
point to the directory that the DLL is compiled in.

Quote:

> > and you can set breakpoints and debug in
> >Fortran.

> >I've inherited some legacy code that makes 1 call to the Fortran DLL,
but
> >it has 48 arguments!

> Can you post or send me the Fortran declaration and export code snip,
> plus the corresponding VB declaration and calling protocol? I've got
> the same problem, except I have to handle 230 or so arrays,
> parameters, etc. Also, I have over 2300 elements and "things" packed
> in a common block that need to be passed in another application. Have
> you seen how to pass common blocks in and out of DLLs?

> > I had a lot of trouble passing the arguments, especially arrays
> >of strings.    The manual is no help whatsoever in doing that -- I finally
had
> >to call Microsoft

> Was this the $95/incident deal? What number did you call?

> > and they pointed me to a file on their website that had
> >the answers that I needed.

> What file was that? What is the address? I found Q181625 by poking
> around in their knowledge base. Is that the same file?

> Jeffrey L. Baldwin
> Mind & Vision Computer Systems
> "Intelligent Processing Systems for the Energy Industry"
> Voice/Fax/Data: (281) 550-4534     (800) MVCSTLM

> http://idt.net/~mvcs



Tue, 21 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

Regarding the original question, it might be helful to try
to look at the following:

(anonymous ftp ??)

ftp.microsoft.com/developr/unsup-ed/510/vb_dll/vb_dll.zip

or perhaps
                 /developr/kb/q129/7/19
for file Q129719...(trailing name .txt or .zip)

August Miller



Wed, 22 Dec 1999 03:00:00 GMT  
 Calling Fortran-DLLs with Visual Basic 4.0

We are calling our fortran-DLL from Delphi-Visual Pascal using LaheyF90.
Chuck Crawford, Toronto
--



Tue, 04 Jan 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Visual Basic 5.0 calling Fujitsu COBOL 4.0 created DLL's

2. Creating - Fortran 77 dll for use in Visual Basic 6.0 (not using Compaq Visual Fortran)

3. HELP : Visual Basic calling FORTRAN DLL

4. HELP : visual basic calling fortran DLL

5. Calling Fortran DLL in VIsual Basic 6.0

6. Calling fortran dll from visual basic

7. Setting up a MS Fortran .DLL/calling from Visual Basic

8. Calling Fortran 77 dll's from Visual Basic under Excel

9. Visual Basic call a Fortran DLL

10. Calling a Visual Basic DLL from a Fortran executable

11. Calling MS Excel Visual Basic functions from Fortran DLL

12. Calling a fortran DLL from Visual Basic

 

 
Powered by phpBB® Forum Software