1
0
forked from 0ad/0ad
0ad/source/ps/DllLoader.h
Ykkrosh 8b7d1fcfb3 * Moved command-line options list from system.cfg into readme.txt. Updated the list to reflect reality. Removed -novbo option because you can use the .cfg file instead.
* Changed log files to trigger standards mode in Firefox (to be
consistent with other browsers), by making it valid HTML5. Changed the
font and some spacing.
 * Made CLogger default to ignoring messages if it hasn't been
initialised yet, instead of crashing.
 * Added leak reporting to the unit tests.
 * Renamed mods/_tests to mods/_test.xero, since it's only used by
Xeromyces and the other tests use mods/_test.otherstuff instead.
 * Fixed Atlas compilation on Windows.
 * Moved Atlas's DLL-loading code into a separate class, so it can be
shared.

This was SVN commit r4707.
2006-12-20 03:09:21 +00:00

64 lines
1.6 KiB
C++

#ifndef DLLLOADER_H__
#define DLLLOADER_H__
#include "ps/Errors.h"
ERROR_GROUP(DllLoader);
ERROR_TYPE(DllLoader, DllNotLoaded);
ERROR_TYPE(DllLoader, SymbolNotFound);
class DllLoader
{
public:
/**
* Prepare the DLL loader. Does no actual work.
*
* @param name base 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).
*/
DllLoader(const char* name);
~DllLoader();
/**
* Attempt to load and initialise the library, if not already. Can be harmlessly
* called multiple times. Returns false if unsuccessful.
*/
bool LoadDLL();
/**
* Check whether the library has been loaded successfully. Returns false
* before {@link #LoadDLL} has been called; otherwise returns the same as
* LoadDLL did.
*/
bool IsLoaded() const;
/**
* Attempt to load a named symbol from the library. If {@link #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.
*
* @throws PSERROR_DllLoader
*/
template <typename T>
void LoadSymbol(const char* name, T& fptr) const;
private:
// Typeless version - the public LoadSymbol hides the slightly ugly
// casting from users.
void LoadSymbolInternal(const char* name, void** fptr) const;
const char* m_Name;
void* m_Handle;
};
template <typename T>
void DllLoader::LoadSymbol(const char* name, T& fptr) const
{
LoadSymbolInternal(name, (void**)&fptr);
}
#endif // DLLLOADER_H__