| GL Studio C++ Runtime API

Public Types | Public Member Functions | Static Public Member Functions | List of all members
DynamicLibrary Class Reference

The DynamicLibrary class. A cross-platform class for loading dynamic link libraries and shared objects. More...

`#include <dynamic_library.h>`

## Public Types
enum | ErrorEnum { ERROR_NONE , ERROR_VERSION_MISMATCH , ERROR_UNKNOWN }
typedef void * | LibHandle_t
| Linux, macOS, and others use a pointer to the opened dynamic library.

## Public Member Functions
| DynamicLibrary (const char *lib_name_arg, bool quiet=false, bool searchLibPath=false, bool tryStandardExtensions=false, bool matchVersion=false)
virtual | ~DynamicLibrary ()
| Destructor for dynamic library object. Closes the library so the OS can cleanup.
virtual FunctionPointer | DynamicFunction (const char *function_name)
virtual bool | Loaded () const
ErrorEnum | LastError () const
const char * | ErrorString () const

## Static Public Member Functions
static bool | Exists (const char *libName, bool tryStandardExtensions=true)
static std::string | Find (const std::string &name)
static void | RemoveExtension (std::string &libpath)

## Detailed Description

The DynamicLibrary class. A cross-platform class for loading dynamic link libraries and shared objects.

## Member Enumeration Documentation

## ◆ ErrorEnum

enum ErrorEnum

Error Enum

Enumerator
ERROR_VERSION_MISMATCH | Load failed due to incompatible GL Studio or compiler versions.
ERROR_UNKNOWN | Load failed for unknown reason (see DynamicLibrary::ErrorString())

## Constructor & Destructor Documentation

## ◆ DynamicLibrary()

DynamicLibrary | ( | const char * | lib_name_arg,
|  | bool | quiet = `false`,
|  | bool | searchLibPath = `false`,
|  | bool | tryStandardExtensions = `false`,
|  | bool | matchVersion = `false`
| ) |  |

Constructor for dynamic library object. Causes the dynamic library which is passed in by filename to be opened.

Parameters

  lib_name_arg | A pointer to a string which is a library name to be opened, may include the path, can not be NULL
  quiet | Whether this class emits error messages or fails silently.
  searchLibPath | Deprecated, unused.
  tryStandardExtensions | If this is true, the file extension, if any, will be stripped off and the appropriate standard extension for the current OS will be appended. If the changed filename cannot be found, then the original filename will be used as a last resort.
  matchVersion | Only load the library if it contains symbols that identify it as a GL Studio RSO, and its version information exactly matches this runtime library.

## Member Function Documentation

## ◆ DynamicFunction()

virtual FunctionPointer DynamicFunction | ( | const char * | function_name | ) |
| virtual

Dynamically resolves a function from the library. The name of the function is passed in.

Parameters

  function_name | A pointer to a string, which represents the Name of a Function to find.

Returns
  Returns a pointer to the function if it is found or NULL otherwise

## ◆ ErrorString()

const char * ErrorString | ( |  | ) | const

Returns
  The last error string or NULL if no error has occurred.

Note
  When tryStandardExtensions == true, this may be very long since it contains the error information for each attempted filename.

## ◆ Exists()

static bool Exists | ( | const char * | libName,
|  | bool | tryStandardExtensions = `true`
| ) |  |
| static

Parameters

  libName | The name of the library to load.
  tryStandardExtensions | If true, will try the standard extensions (i.e. .dll, .so, .dylib).

Returns
  True if the library can be found somewhere on the system, false otherwise.

## ◆ Find()

static std::string Find | ( | const std::string & | name | ) |
| static

Parameters

  name | The name of the file to locate.

Returns
  The full path to the given file name.

## ◆ LastError()

ErrorEnum LastError | ( |  | ) | const

Call LastError() when Loaded() is false to determine to determine if load failure occured due to a version mismatch.

Returns
  The error type, or ERROR_NONE if no failure.

## ◆ Loaded()

virtual bool Loaded | ( |  | ) | const
| virtual

Returns
  True if the library successfully loaded, false otherwise.

## ◆ RemoveExtension()

static void RemoveExtension | ( | std::string & | libpath | ) |
| static

Removes the extension, if any, from the specified path.

Parameters

  libpath | The path to be stripped of extensions.

The documentation for this class was generated from the following file:

- dynamic_library.h