IMPORT Statement  


Load or free a library (DLL) to access an imported procedure.


IMPORT ADDR  ProcName$, LibName$ TO AddrVar& [, HndlVar&]



In most cases, libraries are implicitly loaded automatically when you list an IMPORT or LIB option in a DECLARE statement.  While that's the easiest approach, it can cause a fatal problem if the DLL is missing, or it's a version which does not include the Sub/Function you need.  In that case, your program will fail at startup, and not execute at all.

IMPORT ADDR allows you to load a DLL explicitly, by name, so that you can handle a problem gracefully if the operation fails for any reason.  With IMPORT ADDR, ProcName$ specifies the name of the SUB or Function you wish to access, while LibName$ specifies the name of the DLL and where it is located.  ProcName$ must use the correct upper/lower case for all alphabetic characters or it will fail.  If the load is successful, the address of the entry point of the Sub/Function is assigned to the variable AddrVar&, and the handle of the DLL is assigned to the optional variable HndlVar&.  Both of these variables must be Long Integers or DWords.  If the load fails for any reason, the value zero (0) is assigned to both.

After the library (DLL) is loaded successfully, you can access the Sub/Function with CALL DWORD AddrVar&.

Once you are through using the library, you can release it and regain the memory used by executing IMPORT CLOSE.  The expression LibHndl must specify the value returned in HndlVar& when the DLL was loaded.  If you do not execute an IMPORT CLOSE, the DLL will be automatically released when your program terminates.

See also