Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

Library Class Reference

Shared library loader. More...

#include <cxxtools/library.h>

List of all members.

Public Member Functions

 Library ()
 Default Constructor which does not load a library.
 Library (const std::string &path)
 Loads a shared library.
 Library (const Library &other)
Libraryoperator= (const Library &other)
 ~Library ()
 The destructor unloads the shared library from memory.
Libraryopen (const std::string &path)
 Loads a shared library.
void close ()
void * operator[] (const char *symbol) const
 Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.
void * resolve (const char *symbol) const
 Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.
 operator const void * () const
 Returns null if invalid.
Symbol getSymbol (const char *symbol) const
bool operator! () const
 Returns true if invalid.
const std::string & path () const
 Returns the path to the shared library image.

Static Public Member Functions

static std::string suffix ()
 Returns the extension for shared libraries.
static std::string prefix ()
 Returns the prefix for shared libraries.

Protected Member Functions

void detach ()


Detailed Description

This class can be used to dynamically load shared libraries and resolve symbols from it. The example below shows how to retrieve the address of the function 'myProcedure' in library 'MyLibrary':

        Library shlib("MyLibrary.dll");
        void* procAddr = shlib["myProcedure"];

        typedef int (*MyProcType)();
        MyProcType proc =(MyProcType)procAddr;
        int result = proc();

Constructor & Destructor Documentation

Library ( const std::string &  path  )  [explicit]

If a file could not be found at the given path, the path will be extended by the platform-specific shared library extension first and then also by the shared library prefix. If still no file can be found an exception is thrown.

The library is loaded immediately.


Member Function Documentation

Library& open ( const std::string &  path  ) 

If a file could not be found at the given path, the path will be extended by the platform-specific shared library extension first and then also by the shared library prefix. If still no file can be found an exception is thrown. Calling this method twice might close the previously loaded library.

static std::string suffix (  )  [static]

Returns ".so" on Linux, ".dll" on Windows.

static std::string prefix (  )  [static]

Returns "lib" on Linux, "" on Windows

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6