Callback from Fortran DLL to VB6

From: Mitch (heinemanmc_at_cdm.com)
Date: 12/13/04


Date: 13 Dec 2004 07:48:24 -0800

I've developed a callback example between a Fortran DLL and VB6 for an
integer variable. It works in Compaq Fortran 6.6, but fails in Lahey
Fortran 7.1, which the program I'd like to incorporate the callback
into is developed in. What is wrong with my code? My ultimate goal is
to pass a string to VB, not an integer, so help towards that end would
be even better. I'd appreciate specific code examples if possible.

Thanks for your asssistance,
Mitch Heineman
Cambridge, Massachusetts
(Main languages I've programmed in: APL 1978, Fortran 1982, xBASE 1984,
VB 1995, Avenue 1999. At least Fortran's still around!)

--------------------------------------------------------------------------

'Fortran callback to VB6. Works for CVF; causes protection faults in
Lahey
'VB6 code. Needs a form with a command button and a label
'Form code

Private Sub Command1_Click()
Call Test_DLL(AddressOf Update)
End Sub

'Module code
Declare Sub Test_DLL Lib "Test_DLL" (ByVal cb As Long)
Sub Update(intPCT As Long)
'Debug.Print intPCT
frmMain.Label1.Caption = "running..." & intPCT
frmMain.Refresh
'If intPCT >= 500 Then MsgBox (intPCT)
End Sub

------------------------------------------------------
!Fortran code
Subroutine Test_DLL(update)
!first DLL line for Lahey (lf95 /win /dll /ml msvb); last two for CVF
(DF /dll)
!dll_export Test_DLL
!dec$ attributes dllexport ::Test_DLL
!dec$ attributes alias :'Test_DLL'::Test_DLL

Interface
Subroutine update(i1)
Integer i1
End Subroutine update
End Interface
Integer intPCT

Do intPCT = 1,501
   Call update(intPCT)
End Do
End