1 /************************************************************************* 2 ** DLLoader.cpp ** 3 ** ** 4 ** This file is part of dvisvgm -- the DVI to SVG converter ** 5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de> ** 6 ** ** 7 ** This program is free software; you can redistribute it and/or ** 8 ** modify it under the terms of the GNU General Public License as ** 9 ** published by the Free Software Foundation; either version 3 of ** 10 ** the License, or (at your option) any later version. ** 11 ** ** 12 ** This program is distributed in the hope that it will be useful, but ** 13 ** WITHOUT ANY WARRANTY; without even the implied warranty of ** 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 15 ** GNU General Public License for more details. ** 16 ** ** 17 ** You should have received a copy of the GNU General Public License ** 18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** 19 *************************************************************************/ 20 21 #include <config.h> 22 #include "DLLoader.h" 23 24 DLLoader(const char * dlname)25DLLoader::DLLoader (const char *dlname) : _handle(0) 26 { 27 if (dlname && *dlname) { 28 #ifdef __WIN32__ 29 _handle = LoadLibrary(dlname); 30 #else 31 _handle = dlopen(dlname, RTLD_LAZY); 32 #endif 33 } 34 } 35 36 ~DLLoader()37DLLoader::~DLLoader () { 38 if (_handle) { 39 #ifdef __WIN32__ 40 FreeLibrary(_handle); 41 #else 42 dlclose(_handle); 43 #endif 44 } 45 } 46 47 48 /** Loads a function or variable from the dynamic/shared library. 49 * @param[in] name name of function/variable to load 50 * @return pointer to loaded symbol, or 0 if the symbol could not be loaded */ loadSymbol(const char * name)51void* DLLoader::loadSymbol (const char *name) { 52 if (_handle) { 53 #ifdef __WIN32__ 54 return (void*)GetProcAddress(_handle, name); 55 #else 56 return dlsym(_handle, name); 57 #endif 58 } 59 return 0; 60 } 61