Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

ADLLS()

This function was added in VFP 7 to provide an easy way to find out what API functions have been declared.

Usage

nFunctionCount = ADLLS( aFunctionList )

Parameter

Value

Meaning

aFunctionList

Name

An array to hold the list of declared API functions.

nFunctionCount

Number

The number of API functions declared.

VFP lets you use functions from the Windows API by declaring them (using the DECLARE-DLL command). Prior to VFP 7, the only way to find out programmatically which functions had already been declared was to LIST STATUS to a file, then parse the file. Nasty and error-prone.

ADLLS() makes it easy. It fills an array with the list of declared functions. The new array has three columns. The first contains the actual name of the function. The second contains the alias assigned the function when it was declared—aliases are assigned using the AS clause of DECLARE-DLL. The third column contains the full path and filename of the library containing the function. What’s cool here is that even when you declare a function with the IN WIN32API clause, ADLLS() digs up the name and path of the actual DLL file containing the function.

While you can use this function to figure out whether a particular API function has been declared before doing so, there’s no penalty for declaring a function more than once.

We do wish this function returned one more piece of information: the list of parameter types declared for the function. The problem is that sometimes you might choose to declare some parameter types differently from the actual Win32API declaration, perhaps because VFP handles that type poorly. But if you have two different declarations, calling the function could result in an error. As we say above, since there’s no penalty for the declaring the function more than once, we feel it’s better to declare it each time you use it.

Example

* See whether a particular function was declared.
* Grab the alias, if so, so we can use the function
* without worrying what name it was declared with.
LOCAL nDLLCount, aDLLList[1], nItem, cGSCAlias
nDLLCount = ADLLS( aDLLList )
nItem = ASCAN( aDLLList, "GetSysColor", -1, -1, 1, 14)
IF nItem = 0
  * Declare it
  DECLARE INTEGER GetSysColor IN WIN32API INTEGER nElement
  cGSCAlias = "GetSysColor"
ELSE
  * Grab the defined alias for the function
  cGSCAlias = aDLLList[ nItem, 2 ]
ENDIF

* Now run it
cCommand = cGSCAlias + "(13)"
nResult = EVALUATE(cCommand)
WAIT WINDOW TRANSFORM(nResult)

The example takes advantage of several of the new capabilities of ASCAN()—specifying a particular column, forcing a search to be exact (in the VFP sense), and returning the row number rather than the element number. Because API functions are case-sensitive, the example doesn’t specify a case-insensitive search, another of the new abilities of ASCAN().

See Also

AScan(), Clear DLLS, Declare-DLL, List Status