Arbortext Command Language > Functions by Alphabetical Listing > dl_find
  
dl_find
dl_find(h, symbol)
This function returns the address of the exported dynamic (shared) library function specified by symbol. The parameter h is the identifier of the dynamic library as returned by a previous call to dl_load. The address returned is an identifier that is passed to dl_call to actually invoke the function. dl_find returns 0 if the symbol cannot be found. The function dl_error, if supported by the operating system, may be called to obtain a message describing the reason for failure.
An example of an Arbortext Command Language interface to the Windows API GetProfileString follows.
function GetProfileString(section, key)
{
local dll = dl_load("kernel32")
if (!dll) {
response("Couldn't load kernel32")
return "";
}
local _GetProfileString = dl_find(dll, \
"GetProfileStringA")
if (!_GetProfileString) {
response("Couldn't find GetProfileStringA")
dl_unload(dll)
return ""
}
local buf = pack("a255"); # get a return buffer
dl_call(_GetProfileString, section, key, "", buf, 255)
dl_unload(dll)
return unpack("A*", buf); # trim trailing nulls
}
A sample call would be:
country = GetProfileString("Intl", "sCountry")
If this function is frequently called, or if other APIs from the same DLL are used, it would be better to load the DLL only once and remember the library identifier and function reference in global variables.
See dl_call for additional examples.
Related Topics
dl_call built-in function
dl_error built-in function
dl_load built-in function