Public Member Functions | Static Public Member Functions | List of all members
dynamiclib Class Reference

Public Member Functions

 dynamiclib ()
 ~dynamiclib ()
bool open (const char *library, bool loaddependencies, bool global)
bool close ()
void * getSymbol (const char *symbol) const
char * getError () const

Static Public Member Functions

static void setErrorMutex (threadmutex *mtx)

Detailed Description

The dynamiclib class provides methods for loading, unloading and calling functions from dynamically linked libraries.

Constructor & Destructor Documentation

◆ dynamiclib()

dynamiclib::dynamiclib ( )

Creates an instance of the dynamiclib class.

◆ ~dynamiclib()

dynamiclib::~dynamiclib ( )

Deletes this instance of the dynamiclib class.

Member Function Documentation

◆ close()

bool dynamiclib::close ( )

Closes and unloads the previously opened library.

◆ getError()

char* dynamiclib::getError ( ) const

Returns a human-readable description of the previous error that occurred, or NULL if no error has occurred.

This method allocates a buffer internally and returns it. The calling program must deallocate the buffer.

◆ getSymbol()

void* dynamiclib::getSymbol ( const char *  symbol) const

Returns a handle to "symbol" (exported function or variable) in the currently open library or NULL if an error occurs or if no library is currently open.

◆ open()

bool dynamiclib::open ( const char *  library,
bool  loaddependencies,
bool  global 

Opens library "library". If "loaddependencies" is true, then all libraries required by this library are also loaded, if it is false, they are loaded later, as needed. If "global" is true, then the symbols defined in the library are made available to libraries which are loaded later.

Returns true on success and false on failure.

◆ setErrorMutex()

static void dynamiclib::setErrorMutex ( threadmutex mtx)

getError() is not reentrant and thus not thread safe. If your application is multi-threaded and you use getError(), you must use this method to supply a mutex and ensure thread safety.

If you don't supply a mutex, getError() will still work, but will not be thread-safe.