From: <man...@us...> - 2014-03-10 19:23:44
|
Revision: 3860 http://sourceforge.net/p/modplug/code/3860 Author: manxorist Date: 2014-03-10 19:23:36 +0000 (Mon, 10 Mar 2014) Log Message: ----------- [Ref] Add mpt::Library, a RAII wrapper around LoadLibrary/dlopen with a templated wrapper around GetProcAddress that avoids a lot of verbose casting. Handle almost all OS-specific and OpenMPT/libopenmpt-specific API and path differences of library loading in the wrapper. [Imp] Use stricter DLL search path restrictions on Windows Vista and newer with KB2533623 installed and on Windows 8. [Ref] Convert UXTheme, export codecs, unmo3, libmpg123, sounddev and SoundTouch LoadLibrary calls to mpt::Library. Do not yet convert plugin loading (for now). [Ref] Move loading of UXTheme.dll into CTrackApp. Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/MPTrackUtil.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/sounddev/SoundDeviceThread.cpp trunk/OpenMPT/sounddev/SoundDeviceThread.h trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/common/BuildSettings.h 2014-03-10 19:23:36 UTC (rev 3860) @@ -231,11 +231,6 @@ // fixing stuff up -#if !defined(MODPLUG_TRACKER) && defined(NO_MO3) -// For library builds, windows.h is only required for LoadLibrary. -//#define NO_WINDOWS_H -#endif - #if !defined(ENABLE_MMX) && !defined(NO_REVERB) #define NO_REVERB // reverb requires mmx #endif @@ -289,8 +284,13 @@ #define MPT_WITH_CHARSET_LOCALE // PathString requires locale charset #endif +#if !defined(MODPLUG_TRACKER) && defined(MPT_WITH_DYNBIND) +// For library builds, windows.h is only required for LoadLibrary. +//#define NO_WINDOWS_H +#endif + #if MPT_COMPILER_MSVC #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/common/misc_util.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -17,7 +17,14 @@ #include <time.h> +#if defined(MPT_WITH_DYNBIND) +#if !MPT_OS_WINDOWS +#include <dlfcn.h> +#endif +#endif + + template<typename T> inline T ConvertStrToHelper(const std::string &str) { @@ -433,3 +440,330 @@ } // namespace Util + + +#if defined(MPT_WITH_DYNBIND) + + +namespace mpt +{ + + +#if MPT_OS_WINDOWS + + +// KB2533623 / Win8 +#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS +#define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 +#endif +#ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR +#define LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x00000200 +#endif +#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32 +#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 +#endif +#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR +#define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 +#endif + + +#if !defined(MODPLUG_TRACKER) +// For OpenMPT, this is defined in mptrack/MPTrackUtil.cpp . +mpt::PathString GetAppPath() +{ + return mpt::PathString(); // dummy +} +#endif + +mpt::PathString GetSystemPath() +{ + WCHAR path[MAX_PATH+1]; + MemsetZero(path); + GetSystemDirectoryW(path, MAX_PATH); + return mpt::PathString::FromNative(path) + MPT_PATHSTRING("\\"); +} + + +class LibraryHandle +{ + +private: + + HMODULE hModule; + +public: + + LibraryHandle(const mpt::LibraryPath &path) + : hModule(NULL) + { + + // Check for KB2533623: + bool hasKB2533623 = false; + if(mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWin8) + { + hasKB2533623 = true; + } else if(mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista) + { + HMODULE hKernel32DLL = LoadLibraryW(L"kernel32.dll"); + if(hKernel32DLL) + { + if(::GetProcAddress(hKernel32DLL, "SetDefaultDllDirectories") != nullptr) + { + hasKB2533623 = true; + } + FreeLibrary(hKernel32DLL); + hKernel32DLL = NULL; + } + } + + if(hasKB2533623) + { + switch(path.GetSearchPath()) + { + case mpt::LibrarySearchPathDefault: + hModule = LoadLibraryExW(path.GetFileName().AsNative().c_str(), NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + break; + case mpt::LibrarySearchPathSystem: + hModule = LoadLibraryExW(path.GetFileName().AsNative().c_str(), NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + break; +#if 0 + // Using restricted search paths applies to potential DLL dependencies + // recursively. + // This fails loading for e.g. Codec or Plugin DLLs in application + // directory if they depend on the MSVC C or C++ runtime (which is + // located in the system directory). + // Just rely on the default search path here. + case mpt::LibrarySearchPathApplication: + hModule = LoadLibraryExW(path.GetFileName().AsNative().c_str(), NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + break; + case mpt::LibrarySearchPathFullPath: + hModule = LoadLibraryExW(path.GetFileName().AsNative().c_str(), NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); + break; +#else + case mpt::LibrarySearchPathApplication: + hModule = LoadLibraryW((mpt::GetAppPath() + path.GetFileName()).AsNative().c_str()); + break; + case mpt::LibrarySearchPathFullPath: + hModule = LoadLibraryW(path.GetFileName().AsNative().c_str()); + break; +#endif + } + } else + { + switch(path.GetSearchPath()) + { + case mpt::LibrarySearchPathDefault: + hModule = LoadLibraryW(path.GetFileName().AsNative().c_str()); + break; + case mpt::LibrarySearchPathApplication: + hModule = LoadLibraryW((mpt::GetAppPath() + path.GetFileName()).AsNative().c_str()); + break; + case mpt::LibrarySearchPathSystem: + hModule = LoadLibraryW((mpt::GetSystemPath() + path.GetFileName()).AsNative().c_str()); + break; + case mpt::LibrarySearchPathFullPath: + hModule = LoadLibraryW(path.GetFileName().AsNative().c_str()); + break; + } + } + } + + ~LibraryHandle() + { + if(IsValid()) + { + FreeLibrary(hModule); + } + hModule = NULL; + } + +public: + + bool IsValid() const + { + return (hModule != NULL); + } + + FuncPtr GetProcAddress(const std::string &symbol) const + { + if(!IsValid()) + { + return nullptr; + } + return reinterpret_cast<FuncPtr>(::GetProcAddress(hModule, symbol.c_str())); + } + +}; + + +#else + + +class LibraryHandle +{ + +private: + + void * handle; + +public: + + LibraryHandle(const mpt::LibraryPath &path) + : handle(NULL) + { + handle = dlopen(path.GetFileName().AsNative().c_str(), RTLD_NOW); + } + + ~LibraryHandle() + { + if(IsValid()) + { + dlclose(handle); + } + handle = NULL; + } + +public: + + bool IsValid() const + { + return handle != NULL; + } + + FuncPtr GetProcAddress(const std::string &symbol) const + { + if(!IsValid()) + { + return NULL; + } + return reinterpret_cast<FuncPtr>(dlsym(handle, symbol.c_str())); + } + +}; + + +#endif + + +LibraryPath::LibraryPath(mpt::LibrarySearchPath searchPath, class mpt::PathString const &fileName) +//------------------------------------------------------------------------------------------------ + : searchPath(searchPath) + , fileName(fileName) +{ + return; +} + + +mpt::LibrarySearchPath LibraryPath::GetSearchPath() const +//------------------------------------------------------- +{ + return searchPath; +} + + +mpt::PathString LibraryPath::GetFileName() const +//---------------------------------------------- +{ + return fileName; +} + + +mpt::PathString LibraryPath::GetDefaultPrefix() +//--------------------------------------------- +{ +#if MPT_OS_WINDOWS + return MPT_PATHSTRING(""); +#elif MPT_OS_MACOSX_OR_IOS + return MPT_PATHSTRING("lib"); +#else + return MPT_PATHSTRING("lib"); +#endif +} + + +mpt::PathString LibraryPath::GetDefaultSuffix() +//--------------------------------------------- +{ +#if MPT_OS_WINDOWS + return MPT_PATHSTRING(".dll"); +#elif MPT_OS_MACOSX_OR_IOS + return MPT_PATHSTRING(".dylib"); +#else + return MPT_PATHSTRING(".so"); +#endif +} + + +LibraryPath LibraryPath::App(const mpt::PathString &basename) +//----------------------------------------------------------- +{ + return LibraryPath(mpt::LibrarySearchPathApplication, GetDefaultPrefix() + basename + GetDefaultSuffix()); +} + + +LibraryPath LibraryPath::AppFullName(const mpt::PathString &fullname) +//------------------------------------------------------------------- +{ + return LibraryPath(mpt::LibrarySearchPathApplication, fullname + GetDefaultSuffix()); +} + + +LibraryPath LibraryPath::System(const mpt::PathString &basename) +//-------------------------------------------------------------- +{ + return LibraryPath(mpt::LibrarySearchPathSystem, GetDefaultPrefix() + basename + GetDefaultSuffix()); +} + + +LibraryPath LibraryPath::FullPath(const mpt::PathString &path) +//------------------------------------------------------------ +{ + return LibraryPath(mpt::LibrarySearchPathFullPath, path); +} + + +Library::Library() +//---------------- + : m_Handle(nullptr) +{ + return; +} + + +Library::Library(const mpt::LibraryPath &path) +//-------------------------------------------- + : m_Handle(nullptr) +{ + m_Handle = MPT_SHARED_PTR<LibraryHandle>(new LibraryHandle(path)); +} + + +void Library::Unload() +//-------------------- +{ + *this = mpt::Library(); +} + + +bool Library::IsValid() const +//--------------------------- +{ + return m_Handle && m_Handle->IsValid(); +} + + +FuncPtr Library::GetProcAddress(const std::string &symbol) const +//-------------------------------------------------------------- +{ + if(!IsValid()) + { + return nullptr; + } + return m_Handle->GetProcAddress(symbol); +} + + +} // namespace mpt + + +#endif // MPT_WITH_DYNBIND Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/common/misc_util.h 2014-03-10 19:23:36 UTC (rev 3860) @@ -684,3 +684,110 @@ #endif // WIN32 } // namespace mpt + + +#if defined(MPT_WITH_DYNBIND) + +namespace mpt +{ + + +#if MPT_OS_WINDOWS + +// Returns the application path or an empty string (if unknown), e.g. "C:\mptrack\" +mpt::PathString GetAppPath(); + +// Returns the system directory path, e.g. "C:\Windows\System32\" +mpt::PathString GetSystemPath(); + +#endif // MPT_OS_WINDOWS + + +typedef void* (*FuncPtr)(); // pointer to function returning void* + +class LibraryHandle; + +enum LibrarySearchPath +{ + LibrarySearchPathDefault, + LibrarySearchPathApplication, + LibrarySearchPathSystem, + LibrarySearchPathFullPath, +}; + +class LibraryPath +{ + +private: + + mpt::LibrarySearchPath searchPath; + mpt::PathString fileName; + +private: + + LibraryPath(mpt::LibrarySearchPath searchPath, const mpt::PathString &fileName); + +public: + + mpt::LibrarySearchPath GetSearchPath() const; + + mpt::PathString GetFileName() const; + +public: + + // "lib" on Unix-like systems, "" on Windows + static mpt::PathString GetDefaultPrefix(); + + // ".so" or ".dylib" or ".dll" + static mpt::PathString GetDefaultSuffix(); + + // Returns the library path in the application directory, with os-specific prefix and suffix added to basename. + // e.g.: basename = "unmo3" --> "libunmo3.so" / "apppath/unmo3.dll" + static LibraryPath App(const mpt::PathString &basename); + + // Returns the library path in the application directory, with os-specific suffix added to fullname. + // e.g.: fullname = "libunmo3" --> "libunmo3.so" / "apppath/libunmo3.dll" + static LibraryPath AppFullName(const mpt::PathString &fullname); + + // Returns a system library name with os-specific prefix and suffix added to basename, but without any full path in order to be searched in the default search path. + // e.g.: basename = "unmo3" --> "libunmo3.so" / "unmo3.dll" + static LibraryPath System(const mpt::PathString &basename); + + // Returns a system library name with os-specific suffix added to path. + // e.g.: path = "somepath/foo" --> "somepath/foo.so" / "somepath/foo.dll" + static LibraryPath FullPath(const mpt::PathString &path); + +}; + +class Library +{ +protected: + MPT_SHARED_PTR<LibraryHandle> m_Handle; +public: + Library(); + Library(const mpt::LibraryPath &path); +public: + void Unload(); + bool IsValid() const; + FuncPtr GetProcAddress(const std::string &symbol) const; + template <typename Tfunc> + bool Bind(Tfunc * & f, const std::string &symbol) const + { + #ifdef HAS_TYPE_TRAITS + #if (MPT_COMPILER_MSVC && MPT_MSVC_AT_LEAST(2013,0)) || !MPT_COMPILER_MSVC + // MSVC std::is_function is always false for non __cdecl functions. + // See https://connect.microsoft.com/VisualStudio/feedback/details/774720/stl-is-function-bug . + // Revisit with VS2013. + STATIC_ASSERT(std::is_function<Tfunc>::value); + #endif + #endif + const FuncPtr addr = GetProcAddress(symbol); + f = reinterpret_cast<Tfunc*>(addr); + return (addr != nullptr); + } +}; + +} // namespace mpt + +#endif // MPT_WITH_DYNBIND + Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -1830,16 +1830,15 @@ if(pitch < 0.5f) return 2 + (1<<8); if(pitch > 2.0f) return 2 + (2<<8); - HANDLE handleSt = NULL; - // Check whether the DLL file exists. - HMODULE dllHandle = LoadLibraryW((CTrackApp::GetAppDirPath() + MPT_PATHSTRING("OpenMPT_SoundTouch_f32.dll")).AsNative().c_str()); - if(dllHandle != NULL) + mpt::Library libSoundTouch = mpt::Library(mpt::LibraryPath::AppFullName(MPT_PATHSTRING("OpenMPT_SoundTouch_f32"))); + if(!libSoundTouch.IsValid()) { - FreeLibrary(dllHandle); - handleSt = soundtouch_createInstance(); + MsgBox(IDS_SOUNDTOUCH_LOADFAILURE); + return -1; } - if (handleSt == NULL) + HANDLE handleSt = soundtouch_createInstance(); + if(handleSt == NULL) { MsgBox(IDS_SOUNDTOUCH_LOADFAILURE); return -1; Modified: trunk/OpenMPT/mptrack/MPTrackUtil.cpp =================================================================== --- trunk/OpenMPT/mptrack/MPTrackUtil.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/MPTrackUtil.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -10,11 +10,29 @@ #include "stdafx.h" #include "MPTrackUtil.h" +#include "Mptrack.h" +#include "../common/misc_util.h" #include <io.h> // for _taccess #include <time.h> + +namespace mpt +{ + + +// declared in misc_util.h +mpt::PathString GetAppPath() +//-------------------------- +{ + return theApp.GetAppDirPath(); +} + + +} // namespace mpt + + /* * Loads resource. * [in] lpName and lpType: parameters passed to FindResource(). Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -615,6 +615,7 @@ //-------------------- : m_GuiThreadId(0) , m_pTrackerDirectories(nullptr) + , m_pUXThemeDLL(nullptr) , m_pSettingsIniFile(nullptr) , m_pSettings(nullptr) , m_pTrackerSettings(nullptr) @@ -870,6 +871,10 @@ // Set up paths to store configuration in SetupPaths(cmdInfo.m_bPortable); + // Load UXTheme.DLL + m_pUXThemeDLL = new mpt::Library(mpt::LibraryPath::System(MPT_PATHSTRING("uxtheme"))); + m_pUXThemeDLL->Bind(m_pEnableThemeDialogTexture, "EnableThemeDialogTexture"); + // Construct auto saver instance, class TrackerSettings expects it being available. CMainFrame::m_pAutoSaver = new CAutoSaver(); @@ -1004,6 +1009,9 @@ m_pSettings = nullptr; delete m_pSettingsIniFile; m_pSettingsIniFile = nullptr; + m_pEnableThemeDialogTexture = nullptr; + delete m_pUXThemeDLL; + m_pUXThemeDLL = nullptr; delete m_pTrackerDirectories; m_pTrackerDirectories = nullptr; Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/Mptrack.h 2014-03-10 19:23:36 UTC (rev 3860) @@ -189,6 +189,9 @@ DWORD m_GuiThreadId; TrackerDirectories *m_pTrackerDirectories; + mpt::Library *m_pUXThemeDLL; + typedef HRESULT (WINAPI * pfEnableThemeDialogTexture)(HWND, DWORD); + pfEnableThemeDialogTexture m_pEnableThemeDialogTexture; IniFileSettingsBackend *m_pSettingsIniFile; SettingsContainer *m_pSettings; TrackerSettings *m_pTrackerSettings; @@ -241,6 +244,7 @@ public: bool InGuiThread() const { return GetCurrentThreadId() == m_GuiThreadId; } + HRESULT EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags) { if(m_pEnableThemeDialogTexture) return m_pEnableThemeDialogTexture(hwnd, dwFlags); else return S_OK; } CModDocTemplate *GetModDocTemplate() const { return m_pModTemplate; } CVstPluginManager *GetPluginManager() const { return m_pPluginManager; } SoundDevicesManager *GetSoundDevicesManager() const { return m_pSoundDevicesManager; } Modified: trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -255,7 +255,7 @@ struct LameDynBind { - HMODULE hLame; + mpt::Library hLame; const char* (CDECL * get_lame_version)(); const char* (CDECL * get_lame_short_version)(); @@ -316,31 +316,27 @@ void Reset() { - std::memset(this, 0, sizeof(*this)); + return; } LameDynBind() { Reset(); - if(!hLame) TryLoad(MPT_PATHSTRING("libmp3lame.dll"), true); - if(!hLame) TryLoad(MPT_PATHSTRING("liblame.dll"), true); - if(!hLame) TryLoad(MPT_PATHSTRING("mp3lame.dll"), true); - if(!hLame) TryLoad(MPT_PATHSTRING("lame.dll"), true); - if(!hLame) TryLoad(MPT_PATHSTRING("lame_enc.dll"), false); + if(!hLame.IsValid()) TryLoad(MPT_PATHSTRING("libmp3lame"), true); + if(!hLame.IsValid()) TryLoad(MPT_PATHSTRING("liblame"), true); + if(!hLame.IsValid()) TryLoad(MPT_PATHSTRING("mp3lame"), true); + if(!hLame.IsValid()) TryLoad(MPT_PATHSTRING("lame"), true); + if(!hLame.IsValid()) TryLoad(MPT_PATHSTRING("lame_enc"), false); } - void TryLoad(mpt::PathString filename, bool warn) + void TryLoad(const mpt::PathString &filename, bool warn) { - #ifdef MODPLUG_TRACKER - filename = theApp.GetAppDirPath() + filename; - #endif - hLame = LoadLibraryW(filename.AsNative().c_str()); - if(!hLame) + hLame = mpt::Library(mpt::LibraryPath::AppFullName(filename)); + if(!hLame.IsValid()) { return; } bool ok = true; #define LAME_BIND(f) do { \ - FARPROC pf = GetProcAddress(hLame, #f ); \ - if(!pf) \ + if(!hLame.Bind( f , #f )) \ { \ ok = false; \ if(warn) \ @@ -348,7 +344,6 @@ Reporting::Error(mpt::String::Format("Your '%s' is missing '%s'.\n\nPlease copy a newer 'libmp3lame.dll' into OpenMPT's root directory.", filename, #f ).c_str(), "OpenMPT - MP3 Export"); \ } \ } \ - *reinterpret_cast<void**>(& f ) = reinterpret_cast<void*>(pf); \ } while(0) LAME_BIND(get_lame_version); LAME_BIND(get_lame_short_version); @@ -391,18 +386,15 @@ #undef LAME_BIND if(!ok) { - FreeLibrary(hLame); + hLame.Unload(); Reset(); return; } } - operator bool () const { return hLame ? true : false; } + operator bool () const { return hLame.IsValid() ? true : false; } ~LameDynBind() { - if(hLame) - { - FreeLibrary(hLame); - } + hLame.Unload(); Reset(); } static void GenreEnumCallback(int num, const char *name, void *cookie) @@ -629,7 +621,7 @@ struct BladeDynBind { - HMODULE hBlade; + mpt::Library hBlade; int lame; @@ -641,40 +633,35 @@ void Reset() { - std::memset(this, 0, sizeof(*this)); + lame = 0; } BladeDynBind() { Reset(); - if(!hBlade) + if(!hBlade.IsValid()) { - TryLoad(MPT_PATHSTRING("lame_enc.dll")); - if(hBlade) lame = 1; + TryLoad(MPT_PATHSTRING("lame_enc")); + if(hBlade.IsValid()) lame = 1; } - if(!hBlade) + if(!hBlade.IsValid()) { - TryLoad(MPT_PATHSTRING("bladeenc.dll")); - if(hBlade) lame = 0; + TryLoad(MPT_PATHSTRING("bladeenc")); + if(hBlade.IsValid()) lame = 0; } } - void TryLoad(mpt::PathString filename) + void TryLoad(const mpt::PathString &filename) { - #ifdef MODPLUG_TRACKER - filename = theApp.GetAppDirPath() + filename; - #endif - hBlade = LoadLibraryW(filename.AsNative().c_str()); - if(!hBlade) + hBlade = mpt::Library(mpt::LibraryPath::AppFullName(filename)); + if(!hBlade.IsValid()) { return; } bool ok = true; #define BLADE_BIND(f) do { \ - FARPROC pf = GetProcAddress(hBlade, #f ); \ - if(!pf) \ + if(!hBlade.Bind( f , #f )) \ { \ ok = false; \ } \ - *reinterpret_cast<void**>(& f ) = reinterpret_cast<void*>(pf); \ } while(0) BLADE_BIND(beVersion); BLADE_BIND(beInitStream); @@ -684,18 +671,15 @@ #undef BLADE_BIND if(!ok) { - FreeLibrary(hBlade); + hBlade.Unload(); Reset(); return; } } - operator bool () const { return hBlade ? true : false; } + operator bool () const { return hBlade.IsValid(); } ~BladeDynBind() { - if(hBlade) - { - FreeLibrary(hBlade); - } + hBlade.Unload(); Reset(); } Encoder::Traits BuildTraits() Modified: trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -37,8 +37,8 @@ struct OpusDynBind { - HMODULE hOgg; - HMODULE hOpus; + mpt::Library hOgg; + mpt::Library hOpus; // ogg int (*ogg_stream_init)(ogg_stream_state *os,int serialno); @@ -62,7 +62,7 @@ void Reset() { - std::memset(this, 0, sizeof(*this)); + return; } OpusDynBind() { @@ -73,12 +73,12 @@ }; // start with trying all symbols from a single dll first static const dll_names_t dll_names[] = { - { "libopus-0.dll", "libopus-0.dll" }, - { "libopus.dll" , "libopus.dll" }, - { "opus.dll" , "opus.dll" }, - { "libogg-0.dll" , "libopus-0.dll" }, // official xiph.org builds - { "libogg.dll" , "libopus.dll" }, - { "ogg.dll" , "opus.dll" } + { "libopus-0", "libopus-0" }, + { "libopus" , "libopus" }, + { "opus" , "opus" }, + { "libogg-0" , "libopus-0" }, // official xiph.org builds + { "libogg" , "libopus" }, + { "ogg" , "opus" } }; for(std::size_t i=0; i<CountOf(dll_names); ++i) { @@ -89,34 +89,28 @@ } } } - bool TryLoad(mpt::PathString Ogg_fn, mpt::PathString Opus_fn) + bool TryLoad(const mpt::PathString &Ogg_fn, const mpt::PathString &Opus_fn) { - #ifdef MODPLUG_TRACKER - Ogg_fn = theApp.GetAppDirPath() + Ogg_fn; - Opus_fn = theApp.GetAppDirPath() + Opus_fn; - #endif - hOgg = LoadLibraryW(Ogg_fn.AsNative().c_str()); - if(!hOgg) + hOgg = mpt::Library(mpt::LibraryPath::AppFullName(Ogg_fn)); + if(!hOgg.IsValid()) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hOpus) { FreeLibrary(hOpus); hOpus = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hOpus.IsValid()) { hOpus.Unload(); } return false; } - hOpus = LoadLibraryW(Opus_fn.AsNative().c_str()); - if(!hOpus) + hOpus = mpt::Library(mpt::LibraryPath::AppFullName(Opus_fn)); + if(!hOpus.IsValid()) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hOpus) { FreeLibrary(hOpus); hOpus = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hOpus.IsValid()) { hOpus.Unload(); } return false; } bool ok = true; #define OPUS_BIND(l,f,req) do { \ - FARPROC pf = GetProcAddress( l , #f ); \ - if(!pf && req) \ + if(!l.Bind( f , #f ) && req) \ { \ ok = false; \ } \ - *reinterpret_cast<void**>(& f ) = reinterpret_cast<void*>(pf); \ } while(0) OPUS_BIND(hOgg,ogg_stream_init,true); OPUS_BIND(hOgg,ogg_stream_packetin,true); @@ -132,18 +126,18 @@ #undef OPUS_BIND if(!ok) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hOpus) { FreeLibrary(hOpus); hOpus = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hOpus.IsValid()) { hOpus.Unload(); } Reset(); return false; } return true; } - operator bool () const { return hOgg && hOpus; } + operator bool () const { return hOgg.IsValid() && hOpus.IsValid(); } ~OpusDynBind() { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hOpus) { FreeLibrary(hOpus); hOpus = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hOpus.IsValid()) { hOpus.Unload(); } Reset(); } Encoder::Traits BuildTraits() Modified: trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -22,9 +22,9 @@ struct VorbisDynBind { - HMODULE hOgg; - HMODULE hVorbis; - HMODULE hVorbisEnc; + mpt::Library hOgg; + mpt::Library hVorbis; + mpt::Library hVorbisEnc; // ogg int (*ogg_stream_init)(ogg_stream_state *os,int serialno); @@ -59,7 +59,7 @@ void Reset() { - std::memset(this, 0, sizeof(*this)); + return; } VorbisDynBind() { @@ -71,14 +71,14 @@ }; // start with trying all symbols from a single dll first static const dll_names_t dll_names[] = { - { "libvorbis.dll", "libvorbis.dll" , "libvorbis.dll" }, - { "vorbis.dll" , "vorbis.dll" , "vorbis.dll" }, - { "libogg.dll" , "libvorbis.dll" , "libvorbis.dll" }, // official xiph.org builds - { "ogg.dll" , "vorbis.dll" , "vorbis.dll" }, - { "libogg-0.dll" , "libvorbis-0.dll", "libvorbis-0.dll" }, // mingw builds - { "libogg.dll" , "libvorbis.dll" , "libvorbisenc.dll" }, - { "ogg.dll" , "vorbis.dll" , "vorbisenc.dll" }, - { "libogg-0.dll" , "libvorbis-0.dll", "libvorbisenc-0.dll"} // mingw builds + { "libvorbis", "libvorbis" , "libvorbis" }, + { "vorbis" , "vorbis" , "vorbis" }, + { "libogg" , "libvorbis" , "libvorbis" }, // official xiph.org builds + { "ogg" , "vorbis" , "vorbis" }, + { "libogg-0" , "libvorbis-0", "libvorbis-0" }, // mingw builds + { "libogg" , "libvorbis" , "libvorbisenc" }, + { "ogg" , "vorbis" , "vorbisenc" }, + { "libogg-0" , "libvorbis-0", "libvorbisenc-0"} // mingw builds }; for(std::size_t i=0; i<CountOf(dll_names); ++i) { @@ -89,49 +89,41 @@ } } } - bool TryLoad(mpt::PathString Ogg_fn, mpt::PathString Vorbis_fn, mpt::PathString VorbisEnc_fn) + bool TryLoad(const mpt::PathString &Ogg_fn, const mpt::PathString &Vorbis_fn, const mpt::PathString &VorbisEnc_fn) { - #ifdef MODPLUG_TRACKER - Ogg_fn = theApp.GetAppDirPath() + Ogg_fn; - Vorbis_fn = theApp.GetAppDirPath() + Vorbis_fn; - VorbisEnc_fn = theApp.GetAppDirPath() + VorbisEnc_fn; - #endif - hOgg = LoadLibraryW(Ogg_fn.AsNative().c_str()); - if(!hOgg) + hOgg = mpt::Library(mpt::LibraryPath::AppFullName(Ogg_fn)); + if(!hOgg.IsValid()) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hVorbis) { FreeLibrary(hVorbis); hVorbis = NULL; } - if(hVorbisEnc) { FreeLibrary(hVorbisEnc); hVorbisEnc = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hVorbis.IsValid()) { hVorbis.Unload(); } + if(hVorbisEnc.IsValid()) { hVorbisEnc.Unload(); } return false; } - hVorbis = LoadLibraryW(Vorbis_fn.AsNative().c_str()); - if(!hVorbis) + hVorbis = mpt::Library(mpt::LibraryPath::AppFullName(Vorbis_fn)); + if(!hVorbis.IsValid()) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hVorbis) { FreeLibrary(hVorbis); hVorbis = NULL; } - if(hVorbisEnc) { FreeLibrary(hVorbisEnc); hVorbisEnc = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hVorbis.IsValid()) { hVorbis.Unload(); } + if(hVorbisEnc.IsValid()) { hVorbisEnc.Unload(); } return false; } - hVorbisEnc = LoadLibraryW(VorbisEnc_fn.AsNative().c_str()); - if(!hVorbisEnc) + hVorbisEnc = mpt::Library(mpt::LibraryPath::AppFullName(VorbisEnc_fn)); + if(!hVorbisEnc.IsValid()) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hVorbis) { FreeLibrary(hVorbis); hVorbis = NULL; } - if(hVorbisEnc) { FreeLibrary(hVorbisEnc); hVorbisEnc = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hVorbis.IsValid()) { hVorbis.Unload(); } + if(hVorbisEnc.IsValid()) { hVorbisEnc.Unload(); } return false; } bool ok = true; #define VORBIS_BIND(l,f) do { \ - FARPROC pf = GetProcAddress( l , #f ); \ - if(!pf) \ + if(!l.Bind( f , #f )) \ { \ ok = false; \ } \ - *reinterpret_cast<void**>(& f ) = reinterpret_cast<void*>(pf); \ } while(0) #define VORBIS_BIND_OPTIONAL(l,f) do { \ - FARPROC pf = GetProcAddress( l , #f ); \ - *reinterpret_cast<void**>(& f ) = reinterpret_cast<void*>(pf); \ + l.Bind( f , #f ); \ } while(0) VORBIS_BIND(hOgg,ogg_stream_init); VORBIS_BIND(hOgg,ogg_stream_packetin); @@ -162,20 +154,20 @@ #undef VORBIS_BIND_OPTIONAL if(!ok) { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hVorbis) { FreeLibrary(hVorbis); hVorbis = NULL; } - if(hVorbisEnc) { FreeLibrary(hVorbisEnc); hVorbisEnc = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hVorbis.IsValid()) { hVorbis.Unload(); } + if(hVorbisEnc.IsValid()) { hVorbisEnc.Unload(); } Reset(); return false; } return true; } - operator bool () const { return hOgg && hVorbis && hVorbisEnc; } + operator bool () const { return hOgg.IsValid() && hVorbis.IsValid() && hVorbisEnc.IsValid(); } ~VorbisDynBind() { - if(hOgg) { FreeLibrary(hOgg); hOgg = NULL; } - if(hVorbis) { FreeLibrary(hVorbis); hVorbis = NULL; } - if(hVorbisEnc) { FreeLibrary(hVorbisEnc); hVorbisEnc = NULL; } + if(hOgg.IsValid()) { hOgg.Unload(); } + if(hVorbis.IsValid()) { hVorbis.Unload(); } + if(hVorbisEnc.IsValid()) { hVorbisEnc.Unload(); } Reset(); } Encoder::Traits BuildTraits() Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -1491,35 +1491,16 @@ // This is used for retrieving the correct background colour for the // frames on the general tab when using WinXP Luna or Vista/Win7 Aero. -typedef HRESULT (__stdcall * ETDT)(HWND, DWORD); #include <uxtheme.h> HBRUSH CViewGlobals::OnCtlColor(CDC *pDC, CWnd* pWnd, UINT nCtlColor) //------------------------------------------------------------------- { - static bool bUxInited = false; - static ETDT hETDT = NULL; - - if(!bUxInited) - { - // retrieve path for uxtheme.dll... - WCHAR szPath[MAX_PATH]; - SHGetSpecialFolderPathW(0, szPath, CSIDL_SYSTEM, FALSE); - wcsncat(szPath, L"\\uxtheme.dll", MAX_PATH - (wcslen(szPath) + 1)); - - // ...and try to load it - HMODULE uxlib = LoadLibraryW(szPath); - if(uxlib) - hETDT = (ETDT)GetProcAddress(uxlib, "EnableThemeDialogTexture"); - bUxInited = true; - } - switch(nCtlColor) { case CTLCOLOR_DLG: - if(hETDT) - hETDT(*pWnd, ETDT_ENABLETAB); + theApp.EnableThemeDialogTexture(*pWnd, ETDT_ENABLETAB); + break; } - return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); } Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -26,12 +26,10 @@ m_HasXP = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinXP); - m_hKernel32DLL = NULL; - pCreateWaitableTimer = nullptr; pSetWaitableTimer = nullptr; pCancelWaitableTimer = nullptr; - m_hKernel32DLL = LoadLibrary(TEXT("kernel32.dll")); + m_Kernel32DLL = mpt::Library(mpt::LibraryPath::System(MPT_PATHSTRING("kernel32"))); #if _WIN32_WINNT >= _WIN32_WINNT_WINXP m_HasXP = true; pCreateWaitableTimer = &CreateWaitableTimer; @@ -40,13 +38,18 @@ #else if(m_HasXP && m_hKernel32DLL) { - pCreateWaitableTimer = (FCreateWaitableTimer)GetProcAddress(m_hKernel32DLL, "CreateWaitableTimerA"); - pSetWaitableTimer = (FSetWaitableTimer)GetProcAddress(m_hKernel32DLL, "SetWaitableTimer"); - pCancelWaitableTimer = (FCancelWaitableTimer)GetProcAddress(m_hKernel32DLL, "CancelWaitableTimer"); - if(!pCreateWaitableTimer || !pSetWaitableTimer || !pCancelWaitableTimer) + if(!m_Kernel32DLL.Bind(pCreateWaitableTimer, "CreateWaitableTimerA")) { m_HasXP = false; } + if(!m_Kernel32DLL.Bind(pSetWaitableTimer, "SetWaitableTimer")) + { + m_HasXP = false; + } + if(!m_Kernel32DLL.Bind(pCancelWaitableTimer, "CancelWaitableTimer")) + { + m_HasXP = false; + } } #endif @@ -95,19 +98,12 @@ pSetWaitableTimer = nullptr; pCancelWaitableTimer = nullptr; - if(m_hKernel32DLL) - { - FreeLibrary(m_hKernel32DLL); - m_hKernel32DLL = NULL; - } - } CPriorityBooster::CPriorityBooster(bool boostPriority) //---------------------------------------------------- : m_HasVista(false) - , m_hAvRtDLL(NULL) , pAvSetMmThreadCharacteristics(nullptr) , pAvRevertMmThreadCharacteristics(nullptr) , m_BoostPriority(boostPriority) @@ -119,13 +115,18 @@ if(m_HasVista) { - m_hAvRtDLL = LoadLibrary(TEXT("avrt.dll")); - if(m_hAvRtDLL && m_hAvRtDLL != INVALID_HANDLE_VALUE) + m_AvRtDLL = mpt::Library(mpt::LibraryPath::System(MPT_PATHSTRING("avrt"))); + if(m_AvRtDLL.IsValid()) { - pAvSetMmThreadCharacteristics = (FAvSetMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvSetMmThreadCharacteristicsA"); - pAvRevertMmThreadCharacteristics = (FAvRevertMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvRevertMmThreadCharacteristics"); - } - if(!pAvSetMmThreadCharacteristics || !pAvRevertMmThreadCharacteristics) + if(!m_AvRtDLL.Bind(pAvSetMmThreadCharacteristics, "AvSetMmThreadCharacteristicsA")) + { + m_HasVista = false; + } + if(!m_AvRtDLL.Bind(pAvRevertMmThreadCharacteristics, "AvRevertMmThreadCharacteristics")) + { + m_HasVista = false; + } + } else { m_HasVista = false; } @@ -169,12 +170,6 @@ pAvRevertMmThreadCharacteristics = nullptr; pAvSetMmThreadCharacteristics = nullptr; - if(m_hAvRtDLL) - { - FreeLibrary(m_hAvRtDLL); - m_hAvRtDLL = NULL; - } - } Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-10 19:23:36 UTC (rev 3860) @@ -13,7 +13,9 @@ #include "SoundDevice.h" +#include "../common/misc_util.h" + class CSoundDeviceWithThread; @@ -24,7 +26,7 @@ typedef BOOL (WINAPI *FAvRevertMmThreadCharacteristics)(HANDLE); private: bool m_HasVista; - HMODULE m_hAvRtDLL; + mpt::Library m_AvRtDLL; FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics; FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics; bool m_BoostPriority; @@ -43,7 +45,7 @@ CSoundDeviceWithThread & m_SoundDevice; bool m_HasXP; - HMODULE m_hKernel32DLL; + mpt::Library m_Kernel32DLL; typedef HANDLE (WINAPI *FCreateWaitableTimer)(LPSECURITY_ATTRIBUTES, BOOL, LPCTSTR); typedef BOOL (WINAPI *FSetWaitableTimer)(HANDLE, const LARGE_INTEGER *, LONG, PTIMERAPCROUTINE, LPVOID, BOOL); typedef BOOL (WINAPI *FCancelWaitableTimer)(HANDLE); Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -10,9 +10,6 @@ #include "stdafx.h" #include "Loaders.h" -#ifdef MODPLUG_TRACKER -#include "../mptrack/Mptrack.h" -#endif // MODPLUG_TRACKER bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags) @@ -46,58 +43,59 @@ bool result = false; // Result of trying to load the module, false == fail. // Try to load unmo3 dynamically. -#ifdef _WIN32 -#ifdef MODPLUG_TRACKER - HMODULE unmo3 = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("unmo3.dll")).AsNative().c_str()); -#else - HMODULE unmo3 = LoadLibraryW(MPT_PATHSTRING("unmo3.dll").AsNative().c_str()); -#endif // MODPLUG_TRACKER -#else - void unmo3 = dlopen(MPT_PATHSTRING("libunmo3.so").AsNative().c_str(), RTLD_LAZY); -#endif // _WIN32 + mpt::Library unmo3 = mpt::Library(mpt::LibraryPath::App(MPT_PATHSTRING("unmo3"))); - if(unmo3 == nullptr) + if(!unmo3.IsValid()) { // Didn't succeed. AddToLog(GetStrI18N("Loading MO3 file failed because unmo3.dll could not be loaded.")); } else { // Library loaded successfully. - typedef uint32 (WINAPI * UNMO3_GETVERSION)(); + #if MPT_OS_WINDOWS + #define UNMO3_API WINAPI + #else + #define UNMO3_API + #endif + typedef uint32 (UNMO3_API * UNMO3_GETVERSION)(); // Decode a MO3 file (returns the same "exit codes" as UNMO3.EXE, eg. 0=success) // IN: data/len = MO3 data/len // OUT: data/len = decoded data/len (if successful) // flags & 1: Don't load samples - typedef int32 (WINAPI * UNMO3_DECODE_OLD)(const void **data, uint32 *len); - typedef int32 (WINAPI * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags); + typedef int32 (UNMO3_API * UNMO3_DECODE_OLD)(const void **data, uint32 *len); + typedef int32 (UNMO3_API * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags); // Free the data returned by UNMO3_Decode - typedef void (WINAPI * UNMO3_FREE)(const void *data); + typedef void (UNMO3_API * UNMO3_FREE)(const void *data); + #undef UNMO3_API -#ifdef _WIN32 - UNMO3_GETVERSION UNMO3_GetVersion = (UNMO3_GETVERSION)GetProcAddress(unmo3, "UNMO3_GetVersion"); - void *UNMO3_Decode = GetProcAddress(unmo3, "UNMO3_Decode"); - UNMO3_FREE UNMO3_Free = (UNMO3_FREE)GetProcAddress(unmo3, "UNMO3_Free"); -#else - UNMO3_DECODE UNMO3_Decode = (UNMO3_DECODE)dlsym(unmo3, "UNMO3_Decode"); - UNMO3_FREE UNMO3_Free = (UNMO3_FREE)dlsym(unmo3, "UNMO3_Free"); -#endif // _WIN32 - - if(UNMO3_Decode != nullptr && UNMO3_Free != nullptr) + UNMO3_GETVERSION UNMO3_GetVersion = nullptr; + UNMO3_DECODE_OLD UNMO3_Decode_Old = nullptr; + UNMO3_DECODE UNMO3_Decode = nullptr; + UNMO3_FREE UNMO3_Free = nullptr; + unmo3.Bind(UNMO3_GetVersion, "UNMO3_GetVersion"); + if(UNMO3_GetVersion == nullptr) { + // Old API version: No "flags" parameter. + unmo3.Bind(UNMO3_Decode_Old, "UNMO3_Decode"); + } else + { + unmo3.Bind(UNMO3_Decode, "UNMO3_Decode"); + } + unmo3.Bind(UNMO3_Free, "UNMO3_Free"); + if((UNMO3_Decode != nullptr || UNMO3_Decode_Old != nullptr) && UNMO3_Free != nullptr) + { file.Rewind(); const void *stream = file.GetRawData(); uint32 length = mpt::saturate_cast<uint32>(file.GetLength()); int32 unmo3result; -#ifdef _WIN32 - if(UNMO3_GetVersion == nullptr) + if(UNMO3_Decode != nullptr) { - // Old API version: No "flags" parameter. - unmo3result = static_cast<UNMO3_DECODE_OLD>(UNMO3_Decode)(&stream, &length); + unmo3result = UNMO3_Decode(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1); } else -#endif // _WIN32 { - unmo3result = static_cast<UNMO3_DECODE>(UNMO3_Decode)(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1); + // Old API version: No "flags" parameter. + unmo3result = UNMO3_Decode_Old(&stream, &length); } if(unmo3result == 0) @@ -119,11 +117,6 @@ UNMO3_Free(stream); } } -#ifdef _WIN32 - FreeLibrary(unmo3); -#else - dlclose(unmo3); -#endif // _WIN32 } return result; #endif // NO_MO3 Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2014-03-10 19:17:18 UTC (rev 3859) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2014-03-10 19:23:36 UTC (rev 3860) @@ -12,7 +12,6 @@ #include "stdafx.h" #include "Sndfile.h" #ifdef MODPLUG_TRACKER -#include "../mptrack/Mptrack.h" #include "../mptrack/Moddoc.h" #include "../mptrack/TrackerSettings.h" #endif //MODPLUG_TRACKER @@ -2294,7 +2293,6 @@ //------------------------------------------------------------------ { #ifndef NO_MP3_SAMPLES - static HMODULE mp3lib = nullptr; // Check file for validity, or else mpg123 will happily munch many files that start looking vaguely resemble an MPEG stream mid-file. file.Rewind(); @@ -2340,17 +2338,16 @@ } } -#ifdef MODPLUG_TRACKER - if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("libmpg123-0.dll")).AsNative().c_str()); - if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("libmpg123.dll")).AsNative().c_str()); -#else - if(!mp3lib) mp3lib = LoadLibraryW(MPT_PATHSTRING("libmpg123-0.dll").AsNative().c_str()); - if(!mp3lib) mp3lib = LoadLibraryW(MPT_PATHSTRING("libmpg123.dll").AsNative().c_str()); -#endif // MODPLUG_TRACKER - if(!mp3lib) return false; + mpt::Library mp3lib; - #define MP3_DYNAMICBIND(f) mpg123::pfn_ ## f mpg123_ ## f = (mpg123::pfn_ ## f)GetProcAddress(mp3lib, "mpg123_" #f); if(!mpg123_ ## f) return false + if(!mp3lib.IsValid()) mp3lib = mpt::Library(mpt::LibraryPath::AppFullName(MPT_PATHSTRING("libmpg123-0"))); + if(!mp3lib.IsValid()) mp3lib = mpt::Library(mpt::LibraryPath::AppFullName(MPT_PATHSTRING("libmpg123"))); + if(!mp3lib.IsValid()) mp3lib = mpt::Library(mpt::LibraryPath::AppFullName(MPT_PATHSTRING("mpg123-0"))); + if(!mp3lib.IsValid()) mp3lib = mpt::Library(mpt::LibraryPath::AppFullName(MPT_PATHSTRING("mpg123"))); + if(!mp3lib.IsValid()) return false; + #define MP3_DYNAMICBIND(f) mpg123::pfn_ ## f mpg123_ ## f = nullptr; if(!mp3lib.Bind( mpg123_ ## f , "mpg123_" #f )) return false + MP3_DYNAMICBIND(init); MP3_DYNAMICBIND(new); MP3_DYNAMICBIND(delete); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |