DLL and visibility predicates

dll_load(+Name, -/+Handle, -/+NewFlag)

This predicate run-time loads a DLL. The operating system handle is returned as an integer in Handle. The NewFlag variable will be 1 if this was the first time dll_load/3 was called for this DLL, otherwise it will be 0.


This frees a DLL that was loaded using dll_load/3. The name must exactly match the name used when the DLL was loaded. If NameOrHandle is an integer, then this predicate unloads the DLL of that handle. This is used when the DLL was loaded by some means other than dll_load/3.

dll_handle(?DllName, ?DllHandle)

Translates between Names and Handles.

dll_address(+NameOrHandle, +Item, -/+Address)

This predicate looks up addresses of exported items in a DLL. You can specify the DLL by name or handle. Item is either:

  • An integer: look up the address by ordinal.
  • A predicate specification Func/Arity: look up the name corresponding to the Prolog predicate.
  • An atom: look up the entrypoint by name.

The address is returned as an integer in the Address variable.

dll_visi(+NameOrHandle, +Enable)

DLL's can be built to automatically manage their own visible definitions - adding them when the DLL is loaded and removing them when the DLL is unloaded. This predicate allows additional control over the process. It can be used when the DLL is not built to autoload or it can be used to remove the visible definitions associated with a DLL without unloading the DLL.

NameOrHandle is as in dll_address/3. Set Enable to 1 to add the visible definitions or to 0 to remove them. In order for this predicate to work the DLL must export its visible table definitions.

Determining if a predicate has been built-in


The system/1 predicate determines whether Predicate is an evaluable predicate. The Predicate must be in the form Name/Arity, of which Name and Arity may or may not be instantiated. If you supply an uninstantiated variable for Predicate, then all of the evaluable predicates will be returned through backtracking.


The predicate system/3 is used to set the disable value of an evaluable predicate. When the value is set to 0, the evaluable predicate definition is used. When the value is set to 1, the database is searched for a predicate definition. You can get the value by using the same variable for OldValue and NewValue. Note that if you consult a predicate that is already an evaluable predicate, you will get a warning message but the code will be asserted.

Visibility management predicates

evalAddress(+Goal, -/+Address)

This predicate allows you to look up the address of a predicate in the visible table. Addresses have the form


where CodeType is 1 for Prolog predicates, 2 for eval predicates, and 3 for evalpost predicates. This address can be used by the call/2 predicate.

If the goal is not visible or if the definition has been disabled then the returned address is [0|0].

record_visi(Goal, Type, Offset)

Allows direct access as to what is stored in the visible table for a certain predicate. Type and Offset are as in evalAddress/2.

A use for this predicate might be to make visible a predicate that was defined in a DLL but not declared visible:

?- dll_address(mydll, foo/3, Address),
record_visi(foo(_,_,_), 1, Address).

Another use is to remove a visible definition. To do this, set Type = 0:

record_visi(foo(_,_,_), 0, 0).

system(F/A, -OldDisableFlag, +NewDisableFlag)

This predicate allows you to disable a visible definition. This is different than removing the definition with record_visi/3 because it can later be reinstated.

Typically you call

system(F/A, OldFlag, on)

to disable, then later call

system(F/A, _, OldFlag)

to restore to its former state.


The call/2 predicate inplements indirect call. This is useful for runtime loaded DLL's.

Goal is a Prolog goal.

Address is the structure of the form


where Address is the 32-bit address of the predicate and Code corresponds to the type of the predicate. CodeType is 1 for Prolog predicates, 2 for eval predicates, and 3 for evalpost predicates.