1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File: vogl_dynamic_module.cpp
29 // TODO: Add Linux support!
31 #include "vogl_core.h"
32 #include "vogl_dynamic_module.h"
34 #ifdef VOGL_USE_WIN32_API
35 #include "vogl_winhdr.h"
40 dynamic_module_cache g_dynamic_module_cache;
42 dynamic_module_handle_t load_dynamic_module(const char *pFilename)
44 #if defined(VOGL_ANSI_CPLUSPLUS)
45 VOGL_NOTE_UNUSED(pFilename);
47 #elif defined(VOGL_USE_WIN32_API)
48 return (dynamic_module_handle_t)LoadLibraryA(pFilename);
50 VOGL_NOTE_UNUSED(pFilename);
51 printf("Implement me: load_dynamic_module()\n");
56 void unload_dynamic_module(dynamic_module_handle_t handle)
58 #if defined(VOGL_ANSI_CPLUSPLUS)
59 VOGL_NOTE_UNUSED(handle);
60 #elif defined(VOGL_USE_WIN32_API)
63 FreeLibrary((HMODULE)handle);
66 VOGL_NOTE_UNUSED(handle);
67 printf("Implement me: unload_dynamic_module()\n");
71 void *get_dynamic_module_proc_address(dynamic_module_handle_t handle, const char *pFunc_name)
75 #if defined(VOGL_ANSI_CPLUSPLUS)
76 VOGL_NOTE_UNUSED(handle);
77 VOGL_NOTE_UNUSED(pFunc_name);
79 #elif defined(VOGL_USE_WIN32_API)
80 VOGL_NOTE_UNUSED(handle);
81 return GetProcAddress((HMODULE)handle, pFunc_name);
83 VOGL_NOTE_UNUSED(handle);
84 VOGL_NOTE_UNUSED(pFunc_name);
85 printf("Implement me: get_dynamic_module_proc_address()\n");
90 dynamic_module_cache::dynamic_module_cache()
94 dynamic_module_cache::~dynamic_module_cache()
98 void dynamic_module_cache::unload_all()
100 for (uint i = 0; i < m_modules.size(); i++)
101 unload_dynamic_module(m_modules[i].m_handle);
105 bool dynamic_module_cache::is_module_loaded(const char *pFilename)
107 for (uint i = 0; i < m_modules.size(); i++)
108 if (m_modules[i].m_filename == pFilename)
113 dynamic_module_handle_t dynamic_module_cache::get_module(const char *pFilename)
115 for (uint i = 0; i < m_modules.size(); i++)
116 if (m_modules[i].m_filename == pFilename)
117 return m_modules[i].m_handle;
119 dynamic_module_handle_t handle = load_dynamic_module(pFilename);
123 loaded_module *pModule = m_modules.enlarge(1);
124 pModule->m_filename = pFilename;
125 pModule->m_handle = handle;
129 void *lookup_dynamic_module_func(const char *pModule_filename, const char *pFunc_name)
131 dynamic_module_handle_t mod_handle = dynamic_module_cache::get_global().get_module(pModule_filename);
135 return get_dynamic_module_proc_address(mod_handle, pFunc_name);