ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

How to close a Fortran DLL routine when exiting Visual Basic (front-end) program

(1/5) > >>


I'm having problems with my VB6 program that merges with a Lahey Fortran DLL.  It has been around for over 20 years!  The DLL was started around 5 or 10 years ago.  My VB6 program may call the DLL 1 or more times with no problems.  Then on closing, the program hangs!!!  If one doesn't call the DLL, no hanging occurs on closing.  Ideas?

1. Phil Brubaker
2. S/N: 001873...
3. Lahey/Fujitsu Fortran 95 Express Release 7.10.02
4. Patch level?
5. OS: Windows 7
6. Example VB6 code:
Private Declare Sub PSDcalc_for Lib "PSDcalc_for.dll" (ByVal fileNam As String, ByRef x_array As Single, _
  ByRef spectrum As Single, nptsZ As Integer, npointsZ As Integer, _
  t_startZ As Single, t_finalZ As Single, zeroFillZ As Single, sig2Z As Single, _
  nPoles As Integer, nZeros As Integer, M_eqs As Integer, M_lags As Integer, _
  Mode As Integer, L_pts As Integer, ByVal str_len As Long)

         ReDim x_array(1 To npointsZ) As Single, spectrum(1 To npointsZ) As Single
            x_array(1) = 1: spectrum(1) = 1
            ChDrive App.path:      ChDir App.path

            Call PSDcalc_for(fileTemp, x_array(1), spectrum(1), nptsZ, npointsZ, _
                t_startZ, t_finalZ, zeroFillZ, sig2Z, _
                nPoles, nZeros, M_eqs, M_lags, Mode, L_pts, _

            If nptsZ < 1 Then
              MsgBox "File Error ... read bottom of your '~rainbow.out' file for " & vbCrLf _
                 & "more details. This OUT file is in the same directory " & vbCrLf _
                 & "as your input file; ... " & vbCrLf _
                 & "   " & fileTemp, vbOKOnly, "File name in error ... " _
                 & "read Output file for more"
              Call createFileOut(fileIn)
              Exit Sub
            End If
            Call createFileOut(fileIn)

F90 code:
     Subroutine PSDcalc_for( fileNam, x_array, spectrum, nptsZ, &
           npointsZ, t_startZ, t_finalZ, zeroFillZ, sig2Z, &
           npolesZ, nzerosZ, M_eqsZ, M_lagsZ, modeZ, L_ptsZ)

        dll_export :: PSDcalc_for
        character(len=*) :: fileNam

        include ''

        complex signal_amp( :)
        real y_array( :), norm_factor
        real, dimension( npointsZ) :: x_array, spectrum
        allocatable :: y_array, signal_amp

This code works, can call PSDcalc_for several times ... AOK.  Then try closing my VB6 front-end and vb6 seems to hang.  Create an EXE for my project and it too runs fine until closing.  Then it tries closing and gets the same error msg.

This app has been running since 1994 (?) with no problem, what is new that causes such error?  I found a back-up with same DLL, back in 2015, and it too aborted with same error!  The app is not used that often by me, so unclear when this shutdown error msg. started.

Any ideas on how to close down my Fortran DLL, without forcing it just a 'normal' close?

Thanks, Phil

For Delphi i can use MadExcept to show me easy Errors or non-free'd objects.
I aint program in VB, does it provide Stacktrace? If so, what does it tell?

My guess is that you have some object open that raise a conflict at youre exit-code.

VB, does it provide Stacktrace? If so, what does it tell?
-KodeZwerg (July 17, 2018, 08:46 PM)
--- End quote ---
Never heard of "Stacktrace" in VB nor Fortran ... where might I find it -or- try it?  How would you use it ... show me some code.

Thanks, Phil

The stack trace is from the exception and shows all of the stack frames that results in the execution path to the line in the code.

Article on MSDN about exception handlong in VB

you should also be able to break in the debugger to get the same

using breakpoints on MSDN

How would you use it ... show me some code.-OptimalDesigns (July 18, 2018, 10:57 AM)
--- End quote ---
Hello Phil,
thanks god wraith808 answered, i would have wrote something like that
Visit MadExcept Homepage to get an idea what it does, look at screenshot collection.
Sorry i have no idea if such exist in VB since it isnt my programming language.

How i use it? I just include a file in my project, set up a define, thats all. MadExcept works automatic.
When a program of me crashes where i've included MadExcept, you get a fancy MessageBox with more options and informations.
For your case i would enable a "ReportMemoryLeaks" define, thats all what i need to do in my code. As soon as i quit my App and something isnt free'd yet, MadExcept show me what, the "why" you have to investigate afterwards.

Same Results you get if you debug your code. I would do something like that: (in hope VB have such features)
 - Set up a breakpoint on first line of your exit code
 - Run program normal (inside VB-Studio), work a little with dll functions, close app
    in theory now your debugger should pop-up at first line of your exit code.
    from there trace into code, step-by-step, watch whats on stack
    step so long into; up to the moment when it crash, since your in debugger you see everything in realtime and should be able to locate error.

At least this way i would do it.


[0] Message Index

[#] Next page

Go to full version