Cross-platform support for dynamically loadable libraries

The Dynlibs unit provides support for dynamically loading shared libraries. It is available only on those platforms that support shared libraries. The functionality available here may only be a part of the functionality available on each separate platform, in the interest of portability.

On unix platforms, using this unit will cause the program to be linked to the C library, as most shared libraries are implemented in C and the dynamical linker too.

Library handle type TLibHandle should be considered an opaque type. It is defined differently on various platforms. The definition shown here depends on the platform for which the documentation was generated. Alias for TLibHandle type. Correctly typed Nil handle - returned on error by Load a dynamic library and return a handle to it.

LoadLibrary loads a dynamic library in file Name and returns a handle to it. If the library cannot be loaded, is returned.

No assumptions should be made about the location of the loaded library if a relative pathname is specified. The behaviour is dependent on the platform. Therefore it is best to specify an absolute pathname if possible.

On error, is returned.
Get the address of a procedure or symbol in a dynamic library.

GetProcedureAddress returns a pointer to the location in memory of the symbol ProcName in the dynamically loaded library specified by it's handle lib. If the symbol cannot be found or the handle is invalid, Nil is returned.

On Windows, only an exported procedure or function can be searched this way. On Unix platforms the location of any exported symbol can be retrieved this way.

If the symbol cannot be found, Nil is returned.
Unload a previously loaded library UnloadLibrary unloads a previously loaded library (specified by the handle lib). The call returns True if succesful, False otherwisa. On error, False is returned. For compatibility with Delphi/Windows: Unload a library FreeLibrary provides the same functionality as , and is provided for compatibility with Delphi. For compatibility with Delphi/Windows: Get the address of a procedure GetProcAddress provides the same functionality as , and is provided for compatibility with Delphi. Saves the control word and loads a library SafeLoadLibary saves the FPU control word, and calls with library name Name. After that function has returned, the FPU control word is saved again. (only on Intel i386 CPUS). Extension of shared library SharedSuffix contains the extension of a shared library (dynamically loadable library) on the current platform. It does not contain the . (dot) character. This can be used to determine the name of a shared library in a platform independent way. Pointer to a TLibHandler record. Library loading event handler prototype. TLibEventLoading is the prototype for an event handler (callback) called when a library is being loaded. The function is passed the User parameter passed when calling and a pointer to the TLibHandler record used when loading the library. Library unloading event handler prototype. TLibEventUnloading is the prototype for an event handler (callback) called when a library is being unloaded. The function is passed the pointer to the TLibHandler record used when unloading the library using Pointer to a PLibSymbol type. Pointer to a TLibSymbol type. Library symbol description TLibSymbol describes a symbol address (Name) to be loaded from a library, and the location to write the address (usually a procedural type variable). The address of the library symbol will be written to the location pointed to by pvar. The weak field signals whether the should report an error if the symbol is not found. Set to True means not to report an error, False will cause an error to be reported. Location where to store the symbol address. Name of the symbol to be loaded. False to report an error if the symbol is not found. Library initialization descriptor TLibHandler is used to describe the loading of a library: the name of the library, the symbols to be loaded from the library. Name by which the library is known. list of filenames to try and load the library from Filename of the actually (currently) loaded library. Low-level library handle Loading event, called after the library was loaded. Unloading event, called before the library will be unloaded Number of symbols to load from the library Pointer to an array of symbols to load from the library. Message describing last error during load/unload Reference count for this library Initialize a TLibHandler structure LibraryHandler initializes a new TLibHandler record: it initializes all fields from the parameters that are passed to it, and zeroes out the other fields. It returns the initialized record. None. Try to load a library and initialize a set of symbols

TryInitializeLibrary will attempt to load the library described in Handler, and will attempt to load it from FileName or FileNames if an array of names is provided. When the library is loaded, the addresses of the symbols defined in Handler.Symbols will be loaded and written to the indicated location.

The function returns the reference count of the library (number of times a load was attempted), or -1 on error. An error may occur if the library cannot be loaded or when some required symbols could not be found.

On error, -1 is returned.
Load a library and initialize a set of symbols

InitializeLibrary will attempt to load the library described in Handler, and will attempt to load it from FileName or FileNames if an array of names is provided. When the library is loaded, the addresses of the symbols defined in Handler.Symbols will be loaded and written to the indicated location.

The function returns the reference count of the library (number of times a load was attempted), or raises an exception on error. An error may occur if the library cannot be loaded or when some required symbols could not be found.

On error, a EInOutError exception is raised.
Unload a library ReleaseLibrary will decrease the reference count on Handler and if it reaches zero, the library is unloaded. Append an error to the list of library errors. AppendLibraryError appends Msg to the ErrorMsg field of Handler, with a newline if a message was already present. None. Return the library errors GetLastLibraryError returns the Handler.ErrorMsg field, and empties the field. None. Raise an EInOutError exception RaiseLibraryException raises an EInOutError exception using the error message found in Handler. If no message is found, a default message is used. Load symbol addresses from a library LoadLibrarySymbols loads the addresses of Count symbols described in Symbols, using the library handle Lib. It returns True if all symbols were loaded successfully. If a symbol definition cannot be loaded, a pointer to the definition will be stored in the location pointed to by ErrorSym, and False will be returned. On error, False is returned, and ErrorSym will point to the missing symbol. Clear all library symbols ClearLibrarySymbols clears the addresses of the Count symbol definitions pointed to by Symbols. Return a textual description of the last load error GetLoadErrorStr returns a textual description of the last library loading or unloading error. No other system calls may be made between the load call and the call of GetLoadErrorStr