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

Calling F90 from Excel 97 - Handling "External" functions

avinashs
New Contributor I
328 Views
I want to call a F90 dll in Excel 97. One of the arguments of the F90 program is a subroutine that has been declared "External", say "ESUB". I would like to define ESUB in VBA and pass the name of the argument to the F90 dll. Is this possible in VBA? I know it can be done in VB6.

Avinash Sirdeshpande
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
328 Views
I'm not a VB expert so I can't confirm it -- but the key feature is AddressOf() operator. A quick search in MSDN yielded the following:

Calling a Callback Function
In previous versions of VBA, it is not possible to use callback functions, because there is no way to tell the DLL function which of your own functions you want to call. In order to call a callback function, a DLL function needs a pointer to the callback function's address in memory. Previous versions of VBA do not support pointers to functions. VBA now supports the AddressOf operator, which enables you to pass the address of a VBA function to a DLL.

The Class_Initialize procedure in the ParentWindows collection calls the EnumWindows function, passing the address of EnumWindowsProc for the lpEnumFunc argument, and a reference to the ParentWindow object itself (using the Me keyword) for the lParam argument. Note that the AddressOf operator is followed by the name of the callback function, without any arguments:

Private Sub Class_Initialize()
      
   ' Create new instance of private collection object.
   Set mcolParents = New Collection
   
   ' Add visible parent windows to collection.
   ' Pass Me as reference to ParentWindows collection.
   EnumWindows AddressOf EnumWindowsProc, Me
End Sub

The ParentWindows Class_Initialize event procedure is available in the ParentWindows class module in EnumWindows.xls in the ODEToolsV9SamplesOPGSamplesCH10 subfolder on the Office 2000 Developer CD-ROM.

However, it seems you'll need Office 2000 for that.

Jugoslav
0 Kudos
Reply