Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDLL.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *             D y n a m i c   L i n k   L i b r a r y   S u p p o r t           *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2002,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXDLL_H
00022 #define FXDLL_H
00023 
00024 namespace FX {
00025 
00026 
00027 /**
00028 * Wrap library module handle to allow various operations
00029 * on libraries to be performed.
00030 */
00031 class FXAPI FXDLL {
00032 private:
00033   void *hnd;
00034 public:
00035 
00036   /// Construct with no handle
00037   FXDLL():hnd(NULL){}
00038 
00039   /// Construct with existing handle
00040   FXDLL(void *h):hnd(h){}
00041 
00042   /// Construct copy from original
00043   FXDLL(const FXDLL& org):hnd(org.hnd){}
00044 
00045   /// Return the name of the library module
00046   FXString name() const;
00047 
00048   /// Return library module handle
00049   void* handle() const { return hnd; }
00050 
00051   /// True if library was loaded
00052   FXbool loaded() const { return hnd!=NULL; }
00053 
00054   /// Load the library module from the name
00055   FXbool load(const FXString& nm);
00056 
00057   /// Unload the library module
00058   void unload();
00059 
00060   /// Return the address of the symbol in this library module
00061   void* address(const FXchar* sym) const;
00062   void* address(const FXString& sym) const;
00063 
00064   /// Return the symbol name of the given address
00065   static FXString symbol(void *addr);
00066 
00067   /// Return the name of the library module containing the address
00068   static FXString name(void *addr);
00069 
00070   /// Find DLL containing symbol
00071   static FXDLL dll(void* addr);
00072 
00073   /// Find DLL of ourselves
00074   static FXDLL dll();
00075 
00076   /// Return error message if error occurred loading the library module
00077   static FXString error();
00078   };
00079 
00080 
00081 /**
00082 * Auto DLL wraps a library module handle but also owns it; thus, the library
00083 * module will automatically be unloaded when auto-dll is destroyed.
00084 */
00085 class FXAPI FXAUTODLL : public FXDLL {
00086 private:
00087   FXAUTODLL(const FXAUTODLL&);
00088   FXAUTODLL &operator=(const FXAUTODLL&);
00089 public:
00090 
00091   /// Initialize by loading given library name
00092   FXAUTODLL(const FXString& nm);
00093 
00094   /// Unload library if we have one
00095   ~FXAUTODLL();
00096   };
00097 
00098 
00099 }
00100 
00101 #endif
00102 

Copyright © 1997-2010 Jeroen van der Zijp