Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

What Is an API?

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

API stands for application programming interface. An API is a set of functions you can use to work with a component, application, or operating system. Typically, an API consists of one or more DLLs that provide some specific functionality.

DLLs are files that contain functions that can be called from any application running in Microsoft® Windows®. At run time, a function in a DLL is linked dynamically into an application that calls it. No matter how many applications call a function in a DLL, that function exists only in a single file on the disk, and the DLL is created only when in memory.

The API you probably have heard about most frequently is the Windows API, which includes the DLLs that make up the Windows operating system. Every Windows application interacts with the Windows API directly or indirectly. The Windows API ensures all applications running under Windows will behave in a consistent manner.

Note   As the Windows operating system has evolved, several versions of the Windows API have been published. Windows 3.1 uses the Win16 API. The Microsoft® Windows NT®, Windows 95, and Windows 98 platforms use the Microsoft® Win32® API.

There are other published APIs available in addition to the Windows API. For example, the Mail Application Programming Interface (MAPI) is a set of DLLs that can be used to write e-mail applications.

Traditionally, APIs are written for C and C++ programmers who are building Windows applications, but the functions in a DLL can be called by other programming languages, including VBA. Because most DLLs are written and documented primarily for C and C++ programmers, calling a DLL function might differ somewhat from calling a VBA function. To work with an API, you must understand how to pass arguments to a DLL function.

Caution   Calling the Windows API and other DLL functions can be hazardous to the health of your application. When you call a DLL function directly from your code, you are bypassing some of the safety mechanisms that VBA usually provides for you. If you make a mistake in defining or calling a DLL function (as all programmers eventually do), you might cause an application error (also referred to as a general protection fault, or GPF) in your application. The best strategy is to save your project before you run your code, and to make sure you understand the principles behind calls to DLL functions.

See Also

API Basics | Why Use VBA to Call the Windows API? | API Resources | Accessing Functions in a DLL | Anatomy of a Declare Statement | Constants and User-Defined Types | Understanding Handles

Show:
© 2015 Microsoft