Extending VBA with APIs

Microsoft Visual Basic for Applications (VBA) is a full-featured software development language that offers a vast array of built-in functions so that many Access developers never require anything else.

However, when you start developing more and more complex applications in Access, you may find yourself needing to do things for which VBA does not have a built-in function. Moreover, you'll sometimes need to do things that VBA simply can't do. That's not to say that VBA is incomplete, but, like every other programming language, it does not include every function you're ever likely to need. A line has to be drawn somewhere, and Microsoft drew that line at the functions provided by the API.

The Windows operating system provides a large library of functions that you can access using VBA to extend what you're able to do in your applications. But because the API is inherently VBA-unfriendly, you must first understand what it is, and what special considerations you must take into account to use it from VBA.

This chapter explores what the Windows API is, and why you might want to use it. It describes the libraries that make up the API and how to link them into your application. Then you'll see how to declare API functions to use them with VBA and examine the differences between the data types used in APIs and those used in VBA, learning techniques and formulas to convert between them.

Finally, the chapter introduces the VBA LastDLLError method for dynamic-link library (DLL) error handling and explains how to deploy and install applications that contain references to API or other libraries.

0 0

Post a comment