Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


940


The API functions are written in libraries that can be dynamically linked to Windows applications.
Typically, the functions are contained in dynamic link libraries (DLLs, or .dll files), but they can
also be in .exe, .drv, and .ocx files.

Dynamic linking is a method of making functions available to your applications without hard-
coding them into the executable (.exe) file. In many compiled languages, the code referenced by
an application during development is included in the final product when the executable file is pro-
duced. Binding a library into an application’s executable file is called static linking (also known as
early binding, because the libraries are bound into the executable early in the executable’s life).
Static linking makes for tightly integrated code, but it can also be difficult to manage. The same
type of function may be included in several applications, which can take up space on your user’s
hard drive. In addition, if you need to update or enhance your application, you have to replace the
entire .exe, making those enhancements more difficult to execute.

Dynamic linking, on the other hand, allows you to store a library of code in one place (a DLL) and
reference functions from that library only when they’re needed at runtime. (Dynamic linking is
sometimes called late binding, because the library routines are bound to the executable “late” in the
executable’s life.)

Using DLLs has several advantages:

l It keeps unneeded code out of memory. When calling a function from a DLL, the code
takes up memory only when it’s being used. The memory is reclaimed when the called
function is unloaded.

l (^) As a developer, you can create a host of applications. Rather than include the same code in
each application, you can include only one copy of the DLL and call the functions from all
your applications. This gives your applications a smaller footprint.
l It allows you to update or enhance just the DLL, without replacing all the applications
that use its code.
Although you can’t create DLLs in Microsoft Access, you can certainly use functions stored in the
DLLs underlying Microsoft Windows. As you’ll see in the “How to Use the Windows API” section,
later in this chapter, calling functions stored in the Windows DLLs involves following certain rules.
Generally speaking, you must declare a Windows API call before using it in your code, and most
API functions are rather fussy about the parameters used in the VBA statements calling them. But
overall, the benefits to be gained from using the API functions greatly outweigh the relatively short
learning curve necessary to master them.
Reasons to Use the Windows API
There are many reasons why you should consider using the Windows API (and other application
programming interfaces). Here are a few, in addition to the ones listed in the preceding section.

Free download pdf