00001 /* 00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net) 00003 This file is part of Beesnest. 00004 00005 Beesnest is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 Beesnest is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Beesnest; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 /* DcDynamicLibrary.h: interface for the CdcDynamicLibrary class. */ 00021 00022 #ifndef __CDC_DYNAMIC_LIBRARY 00023 #define __CDC_DYNAMIC_LIBRARY 00024 00025 #include "../DcGlobals.h" 00026 00027 /** 00028 * This class is a wrapper that loads functions from dll/sa (dynamic library). 00029 * It loads the library in the Constructor, and frees it in the Destructor. 00030 * <p> 00031 * @author Erez Bibi 00032 * @version 1.0 00033 */ 00034 class CdcDynamicLibrary 00035 { 00036 private: 00037 HINSTANCE hLib; 00038 CdcString sLibName; 00039 CdcString sLastError; 00040 00041 public: 00042 00043 /** 00044 * Constructor - Loads the library. 00045 * <p> 00046 * @param name The library name (and path). 00047 */ 00048 CdcDynamicLibrary (const CdcString& name); 00049 00050 /** 00051 * Destructor - Frees the library. 00052 */ 00053 ~CdcDynamicLibrary (); 00054 00055 /** 00056 * Returns a pointer to a function in the library. It access the function 00057 * by it's name. The caller must cast this pointer to the function pointer! 00058 * If the function cannot be found in the library, or if the library cannot 00059 * be loaded, GetFunctionByName will return NULL. The error message can 00060 * be retrieved from GetLastError 00061 * <p> 00062 * @param func_name The name of the function in the library. 00063 * @return (void*) A pointer to this function as pointer to void. 00064 */ 00065 void* GetFunctionByName (const CdcString& func_name); 00066 00067 /** 00068 * Returns True if the library is loaded. 00069 */ 00070 bool IsLoaded () 00071 { return hLib != NULL; } 00072 00073 /** 00074 * Return the last error message, or an empty string. 00075 */ 00076 CdcString GetLastError () 00077 { return sLastError; } 00078 00079 /** 00080 * Return the dynamic library name. 00081 */ 00082 CdcString GetLibraryName () 00083 { return sLibName; } 00084 00085 }; 00086 00087 #endif /* __CDC_DYNAMIC_LIBRARY */ 00088