next up previous contents index
Next: Static Linking Up: Foreign Language Interface Previous: Dynamic Linking of shared   Contents   Index


Using the library shlib for DLL and so files

This section discusses the functionality of the (autoload) library shlib.pl, providing an interface to shared libraries. This library can only be used if the prolog-flag open_shared_object is enabled.

load_foreign_library2+Lib, +Entry Search for the given foreign library and link it to the current SWI-Prolog instance. The library may be specified with or without the extension. First, absolute_file_name3 is used to locate the file. If this succeeds, the full path is passed to the low-level function to open the library. Otherwise, the plain library name is passed, exploiting the operating-system defined search mechanism for the shared library. The file_search_path2 alias mechanism defines the alias foreign, which refers to the directories plhome/lib/arch and plhome/lib, in this order.

If the library can be loaded, the function called Entry will be called without arguments. The return value of the function is ignored.

The Entry function will normally call PL_register_foreign to declare functions in the library as foreign predicates. load_foreign_library1+Lib Equivalent to load_foreign_library2. For the entry-point, this function first identifies the `base-name' of the library, which is defined to be the file-name with path nor extension. It will then try the entry-point install-base. On failure it will try to function install(). Otherwise no install function will be called. unload_foreign_library1+Lib If the foreign library defines the function uninstall_base() or uninstall(), this function will be called without arguments and its return value is ignored. Next, abolish2 is used to remove all known foreign predicates defined in the library. Finally the library itself is detached from the process. current_foreign_library2-Lib, -Predicates Query the currently loaded foreign libraries and their predicates. Predicates is a list with elements of the form Module:Head, indicating the predicates installed with PL_register_foreign when the entry-point of the library was called.

msgbox connects a Windows message-box using a foreign function. This example was tested using Windows NT and Microsoft Visual C++ 2.0.

Figure: MessageBox() example in Windows NT
\begin{figure}\begin{code}
...



Subsections
next up previous contents index
Next: Static Linking Up: Foreign Language Interface Previous: Dynamic Linking of shared   Contents   Index
Dr. Richard Botting 2001-12-12