Wrapping DLL Functions
If you call DLL functions frequently, you might want to simplify the process by encapsulating those functions within class modules. By creating a property or method that calls one or more DLL functions, you can work with DLL functions in an object-oriented manner more typical of Microsoft® Visual Basic® for Application (VBA). In addition, because declaring and calling DLL functions can be a difficult and error-prone experience, packaging calls to DLL functions in reusable objects can save you from having to repeat this experience every time you must call the API.
In This Section
- Encapsulating the DLL
When you encapsulate DLL function calls in a class module, you are defining a VBA interface for those functions. - What Is a Callback Function?
To call a function that requires a callback function, you write a VBA function that calls the DLL function, and then the DLL function calls another VBA function, the callback function, that you have defined in your project. - Creating a Callback Function
You can determine whether a DLL function requires a callback function by looking at its arguments and reading the documentation for the function. - Calling a Callback Function
To call a callback function, a DLL function must have a pointer to the callback function's address in memory.
Related Sections
- The Windows API and Other Dynamic-Link Libraries
One of the most powerful features of Visual Basic for Applications (VBA) is its extensibility. You can extend your applications by calling functions in the Microsoft® Windows® application programming interface (API) and other dynamic-link libraries (DLLs). - API Basics
The purpose of the Microsoft® Windows® API is to make it possible for you to develop programs consistent with the Windows operating system and user interface. - Calling DLL Functions
Although calling DLL functions is in many ways similar to calling VBA functions, there are differences that might make DLL functions confusing at first.