diff options
author | David Robillard <d@drobilla.net> | 2018-01-21 00:41:34 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-01-21 00:56:50 +0100 |
commit | 001b459dfaf5d2ed53e4f7a5daea2a408aba1a2d (patch) | |
tree | 165e5620da80f2f9ad6dc0da603932973b461791 /src/Library.cpp | |
parent | a99b72e4adbc4c28fadc08d29299d99405f72db9 (diff) | |
download | ingen-001b459dfaf5d2ed53e4f7a5daea2a408aba1a2d.tar.gz ingen-001b459dfaf5d2ed53e4f7a5daea2a408aba1a2d.tar.bz2 ingen-001b459dfaf5d2ed53e4f7a5daea2a408aba1a2d.zip |
Replace Glib::Module
Diffstat (limited to 'src/Library.cpp')
-rw-r--r-- | src/Library.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Library.cpp b/src/Library.cpp new file mode 100644 index 00000000..148b27d0 --- /dev/null +++ b/src/Library.cpp @@ -0,0 +1,56 @@ +/* + This file is part of Ingen. + Copyright 2018 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "ingen/Library.hpp" + +#ifdef _WIN32 +# include <windows.h> +# define dlopen(path, flags) LoadLibrary(path) +# define dlclose(lib) FreeLibrary((HMODULE)lib) +# define dlerror() "unknown error" +#else +# include <dlfcn.h> +#endif + +namespace Ingen { + +Library::Library(const FilePath& path) : _lib(dlopen(path.c_str(), RTLD_NOW)) +{} + +Library::~Library() +{ + dlclose(_lib); +} + +Library::VoidFuncPtr +Library::get_function(const char* name) +{ +#ifdef _WIN32 + return (VoidFuncPtr)GetProcAddress((HMODULE)_lib, name); +#else + typedef VoidFuncPtr (*VoidFuncGetter)(void*, const char*); + VoidFuncGetter dlfunc = (VoidFuncGetter)dlsym; + return dlfunc(_lib, name); +#endif +} + +const char* +Library::get_last_error() +{ + return dlerror(); +} + +} // namespace Ingen |