- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Avinash Sirdeshpande
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
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
![](/skins/images/06022F5BB6D2F28C8F102671A0F06E85/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page