Dynamically Loading Link Libraries Overview

Description of Polymorphic DLLs.

Purpose

Dynamically load libraries during program execution.

These interfaces are used by programs that need to load libraries at run-time, that have a common interface, but different concrete behavior. Because of this relationship between interface and behaviour, such libraries are called polymorphic DLLs.

Architectural relationships

Many parts of the system use polymorphic DLLs. Communications components, such as Sockets and Messaging, use architectures in which particular communications protocols are provided as polymorphic DLLs, and are loaded as needed. UI application programs are also polymorphic DLLs that are loaded when the user starts the program.

Description

The API has three key concepts: polymorphic DLL, polymorphic DLL handle, and polymorphic DLL function pointer.

Polymorphic DLL

A program that uses a type of polymorphic DLLs defines their interface in terms of a single abstract class whose functions are declared as pure virtual. Each type of polymorphic DLL is given a unique identifier (UID).

A particular concrete DLL:

  • implements the interface by defining and implementing a concrete class derived from the abstract class.

  • exports a function that creates an object of the derived class type. All other functions in the DLL are virtual and called through the base class interface.

Polymorphic DLL handle

The polymorphic DLL handle allows a program to load and close a particular polymorphic DLL. It also allows the caller to obtain pointers to functions exported by the DLL. The system can check that a polymorphic DLL is of the correct type by checking the type UID value.

The polymorphic DLL handle interface is provided by RLibrary.

A wildcard file system search for polymorphic DLLs can be done through TFindLibrary.

Polymorphic DLL function pointer

An exported function is called through a pointer to function obtained through a polymorphic DLL handle.

The polymorphic DLL function pointer type is provided by the TLibraryFunction typedef. The caller casts the pointer to the real type of the exported function before using it.

Related concepts
UID Manipulation Overview