Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


944


Listing 27.2 shows the same declaration using Basic syntax instead of C/C++ syntax. Notice how the
C/C++ data types are converted to their VBA equivalents.

LISTING 27.2
Visual Basic Declaration for GetPrivateProfileString

Declare Function GetPrivateProfileStringA lib “Kernel32”( _
ByVal lpszSection As String,
ByVal lpszKey As String, _
ByVal lpszDefault As String, _
ByVal dwReturnBuffer As Long, _
ByVal cchReturnBuffer As Long, _
ByVal lpszFile As String) As Long

Caution
You must declare the correct data types in your applications. Failure to do so can result in the dreaded General
Protection Fault, crashing your Access application. If you don’t declare variables of the proper size (such as
using an integer when a long is specified), your function calls might overwrite memory locations allocated to
other applications. Using inappropriate data types as parameters to API functions is the most common cause of
problems when using the Windows API.


In Listing 27.2, notice the prefix attached to each argument passed to the functions. These are
standard prefixes used throughout most of the API documentation you’ll find. Some of the more
common prefixes are shown in Table 27.2.

TABLE 27.2

Common Windows API Argument Prefi xes


Prefix C/C++ Data Type VBA Data Type
lpsz Long pointer to a null terminated string String
dw DWORD Long
w WORD Integer
hWnd HANDLE Long
b BOOL Long
l LONG Long
Free download pdf