diff options
author | 2016-05-28 04:14:15 +0200 | |
---|---|---|
committer | 2016-06-11 20:14:09 +0200 | |
commit | 58dc78b6eba373d88fe7ef68f9ce3c2c43e635d6 (patch) | |
tree | 90af8c2c2323070c2c336153de8376d83a3f1f44 /src/osd/windows/winutil.cpp | |
parent | ea1b66f146e4c6663e06b124f8665f878c43ce0c (diff) |
Introduce dynamic_module
This is a central cross-platform facility to dynamically bind functions from shared libraries.
Updated all OSD modules to use it.
Diffstat (limited to 'src/osd/windows/winutil.cpp')
-rw-r--r-- | src/osd/windows/winutil.cpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/osd/windows/winutil.cpp b/src/osd/windows/winutil.cpp index 3574f00f398..880e9aa7a06 100644 --- a/src/osd/windows/winutil.cpp +++ b/src/osd/windows/winutil.cpp @@ -111,67 +111,3 @@ HMODULE WINAPI GetModuleHandleUni() VirtualQuery((LPCVOID)GetModuleHandleUni, &mbi, sizeof(mbi)); return (HMODULE)mbi.AllocationBase; } - -//----------------------------------------------------------- -// Lazy loaded function using LoadLibrary / GetProcAddress -//----------------------------------------------------------- - -lazy_loaded_function::lazy_loaded_function(const char * name, const wchar_t* dll_name) - : lazy_loaded_function(name, &dll_name, 1) -{ -} - -lazy_loaded_function::lazy_loaded_function(const char * name, const wchar_t** dll_names, int dll_count) - : m_name(name), m_module(nullptr), m_initialized(false), m_pfn(nullptr) -{ - for (int i = 0; i < dll_count; i++) - m_dll_names.push_back(std::wstring(dll_names[i])); -} - -lazy_loaded_function::~lazy_loaded_function() -{ - if (m_module != nullptr) - { - FreeLibrary(m_module); - m_module = nullptr; - } -} - -int lazy_loaded_function::initialize() -{ - if (m_module == nullptr) - { - for (int i = 0; i < m_dll_names.size(); i++) - { - m_module = LoadLibraryW(m_dll_names[i].c_str()); - if (m_module != nullptr) - break; - } - - if (m_module == nullptr) - { - osd_printf_verbose("Could not find DLL to dynamically link function %s.\n", m_name.c_str()); - return ERROR_DLL_NOT_FOUND; - } - } - - if (m_pfn == nullptr) - { - m_pfn = GetProcAddress(m_module, m_name.c_str()); - if (m_pfn == nullptr) - { - osd_printf_verbose("Could not find function address to dynamically link function %s.\n", m_name.c_str()); - return ERROR_NOT_FOUND; - } - } - - m_initialized = true; - - return 0; -} - -void lazy_loaded_function::check_init() const -{ - if (!m_initialized) - fatalerror("Attempt to use function pointer for function %s prior to init!", name()); -} |