diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/loadlib.cpp | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Wasabi/bfc/loadlib.cpp')
-rw-r--r-- | Src/Wasabi/bfc/loadlib.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/loadlib.cpp b/Src/Wasabi/bfc/loadlib.cpp new file mode 100644 index 00000000..8682cd29 --- /dev/null +++ b/Src/Wasabi/bfc/loadlib.cpp @@ -0,0 +1,85 @@ +#include "precomp_wasabi_bfc.h" + +#include "loadlib.h" + +#if !defined(WIN32) && !defined(LINUX) +#error port me +#endif + +Library::Library(const wchar_t *filename) : NamedW(filename) +{ + lib = NULL; +} + +Library::~Library() +{ + unload(); +} + +int Library::load(const wchar_t *newname) +{ + if (lib != NULL && newname == NULL) + return 1; + unload(); + if (newname != NULL) + setName(newname); + + const wchar_t *n = getName(); + ASSERT(n != NULL); +#ifdef WIN32 + __try { + lib = LoadLibraryW(n); + } __except(EXCEPTION_EXECUTE_HANDLER) + { + // stupid DLL + lib = NULL; + OutputDebugString(L"exception while loading dll"); + OutputDebugStringW(newname); + OutputDebugString(L"\n"); + } +#elif defined(LINUX) + // Not using string to try to not use common/wasabi in Studio.exe + char *conv = _strdup( getName() ); + int len = strlen( conv ); + if ( ! strcasecmp( conv + len - 4, ".dll" ) ) + { + strcpy( conv + len - 4, ".so" ); + } + + lib = dlopen(conv, RTLD_LAZY); + + free( conv ); +#else +#error port me! +#endif + if (lib == NULL) return 0; + return 1; +} + +void Library::unload() +{ + if (lib != NULL) + { +#ifdef WIN32 + FreeLibrary(lib); +#elif defined(LINUX) + dlclose(lib); +#else +#error port me! +#endif + + } + lib = NULL; +} + +void *Library::getProcAddress(const char *procname) +{ + ASSERT(procname != NULL); +#if defined(WIN32) + return GetProcAddress(lib, procname); +#elif defined(LINUX) + return dlsym(lib, procname); +#else +#error port me! +#endif +} |