Export (0) Print
Expand All
3 out of 5 rated this helpful - Rate this topic

Calling DLL Functions

Although calling DLL functions is in many ways similar to calling Microsoft® Visual Basic® for Applications (VBA) functions, there are differences that might make DLL functions confusing at first. This section addresses how arguments are typed and prefixed in DLL functions, how to return a string, how to pass a data structure, what return values you can expect, and how to retrieve error information.

In This Section

Argument Data Types
The data types used in C and C++, and the notation used to describe them, differ from those used in Microsoft® Visual Basic® for Applications (VBA).
Returning Strings from DLL Functions
DLL functions do not return strings in the same way VBA functions do. Because strings always are passed to DLL functions by reference, the DLL function can modify the value of the string argument.
Passing User-Defined Types
Many DLL functions require you to pass in a data structure by using a predefined format.
Using the Any Data Type
Some DLL functions have an argument that can take more than one type of data. In the Declare statement for a DLL function, such an argument is declared as type Any.
Retrieving Error Information Following DLL Function Calls
Run-time errors that occur in DLL functions behave differently from run-time errors in VBA in that no error message box is displayed.

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.
Wrapping DLL Functions
If you call DLL functions frequently, you might want to simplify the process by encapsulating those functions within class modules.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.