• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/Windows/DcDynamicLibrary.cpp

Go to the documentation of this file.
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 /**
00021  * DcDynamicLibrary.cpp: implementation of the CdcDynamicLibrary class.
00022  * for documentation see the header file.
00023  */
00024 
00025 #include "DcDynamicLibrary.h"
00026 
00027 
00028 CdcDynamicLibrary::CdcDynamicLibrary (const CdcString& name)
00029 {
00030     sLastError = EMPTY_STR;
00031     sLibName = name;
00032     hLib = LoadLibrary (sLibName.GetBuffer ());
00033     if (hLib == NULL)
00034         sLastError = "Cannot load library " + sLibName;
00035 }
00036 
00037 CdcDynamicLibrary::~CdcDynamicLibrary ()
00038 {
00039     if (IsLoaded ())
00040         FreeLibrary ((HMODULE)hLib);
00041 }
00042 
00043 void* CdcDynamicLibrary::GetFunctionByName (const CdcString& func_name)
00044 {
00045     if (IsLoaded () == false)
00046     {
00047         sLastError = "Cannot load library " + sLibName;
00048         return NULL;
00049     }
00050 
00051     void* func = (void*)GetProcAddress ((HMODULE)hLib, func_name.GetBuffer ());
00052     if (func == NULL)
00053         sLastError = "Cannot load function " + func_name + " from " + sLibName;
00054     return func;
00055 }
00056 

Generated on Mon Oct 11 2010 16:23:25 for Beesnest by  doxygen 1.7.2