Pyrogenesis trunk
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
DllLoader Class Reference

#include <DllLoader.h>

Public Member Functions

 DllLoader (const char *name, CLogger::ELogMethod loadErrorLogMethod=CLogger::Error)
 Prepare the DLL loader. More...
 
 ~DllLoader ()
 
bool LoadDLL ()
 Attempt to load and initialise the library, if not already. More...
 
bool IsLoaded () const
 Check whether the library has been loaded successfully. More...
 
void Unload ()
 Unload the library, if it has been loaded already. More...
 
template<typename T >
void LoadSymbol (const char *name, T &fptr) const
 Attempt to load a named symbol from the library. More...
 

Static Public Member Functions

static void OverrideLibdir (const char *libdir)
 Override the build-time setting of the directory to search for libraries. More...
 
static CStr GenerateFilename (const CStr &name, const CStr &suffix, const CStr &extension)
 

Private Member Functions

void LoadSymbolInternal (const char *name, void **fptr) const
 
void LogLoadError (const char *errors)
 

Private Attributes

const char * m_Name
 
void * m_Handle
 
CLogger::ELogMethod m_LoadErrorLogMethod
 

Constructor & Destructor Documentation

◆ DllLoader()

DllLoader::DllLoader ( const char *  name,
CLogger::ELogMethod  loadErrorLogMethod = CLogger::Error 
)

Prepare the DLL loader.

Does no actual work.

Parameters
namebase name of the library (from which we'll derive "name.dll", "libname_dbg.so", etc). Pointer must remain valid for this object's lifetime (which is fine if you just use a string literal).
loadErrorLogMethodAllows to set the CLogger log level that is used when the DllLoader reports loading errors.

◆ ~DllLoader()

DllLoader::~DllLoader ( )

Member Function Documentation

◆ GenerateFilename()

CStr DllLoader::GenerateFilename ( const CStr &  name,
const CStr &  suffix,
const CStr &  extension 
)
static

◆ IsLoaded()

bool DllLoader::IsLoaded ( ) const

Check whether the library has been loaded successfully.

Returns false before LoadDLL has been called; otherwise returns the same as LoadDLL did.

◆ LoadDLL()

bool DllLoader::LoadDLL ( )

Attempt to load and initialise the library, if not already.

Can be harmlessly called multiple times. Returns false if unsuccessful.

◆ LoadSymbol()

template<typename T >
void DllLoader::LoadSymbol ( const char *  name,
T fptr 
) const

Attempt to load a named symbol from the library.

If IsLoaded is false, throws PSERROR_DllLoader_DllNotLoaded. If it cannot load the symbol, throws PSERROR_DllLoader_SymbolNotFound. In both cases, sets fptr to NULL. Otherwise, fptr is set to point to the loaded function.

Exceptions
PSERROR_DllLoader

◆ LoadSymbolInternal()

void DllLoader::LoadSymbolInternal ( const char *  name,
void **  fptr 
) const
private

◆ LogLoadError()

void DllLoader::LogLoadError ( const char *  errors)
private

◆ OverrideLibdir()

void DllLoader::OverrideLibdir ( const char *  libdir)
static

Override the build-time setting of the directory to search for libraries.

◆ Unload()

void DllLoader::Unload ( )

Unload the library, if it has been loaded already.

(Usually not needed, since the destructor will unload it.)

Member Data Documentation

◆ m_Handle

void* DllLoader::m_Handle
private

◆ m_LoadErrorLogMethod

CLogger::ELogMethod DllLoader::m_LoadErrorLogMethod
private

◆ m_Name

const char* DllLoader::m_Name
private

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