Mstdlib-1.24.0
m_module.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_MODULE_H__
25#define __M_MODULE_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31
32#ifdef _WIN32
33#include <windows.h> /* Needed for HMODULE below */
34#endif
35/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37__BEGIN_DECLS
38
39
40/*! \addtogroup m_module Dynamic Module Loading Subsystem
41 * \ingroup m_sql
42 *
43 * Dynamic Module Loading Subsystem
44 *
45 * @{
46 */
47
48/*! Type for returned handle for M_module_load() */
49#ifdef _WIN32
50typedef HMODULE M_module_handle_t;
51#else
52typedef void * M_module_handle_t;
53#endif
54
55/*! Value for an invalid module handle */
56#define M_MODULE_INVALID_HANDLE NULL
57
58/*! Load a module
59 *
60 * The module should be a dynamic loadable module for the operating system.
61 * The subsystem will attempt to search for the module in multiple paths and
62 * multiple file name extensions.
63 *
64 * There is no need to supply a suffix like .so, .dll, or .dylib.
65 *
66 * \param[in] module_name module name to load, no suffix necessary.
67 * \param[out] error user-supplied error message buffer
68 * \param[in] error_size size of user-supplied error message buffer
69 * \return M_MODULE_INVALID_HANDLE on failure, otherwise a valid handle.
70 */
71M_API M_module_handle_t M_module_load(const char *module_name, char *error, size_t error_size);
72
73
74/*! Retrieve a pointer to a symbol in the module
75 *
76 * \param[in] handle Loaded module handle from M_module_load(), or M_MODULE_INVALID_HANDLE to attempt
77 * to load a symbol from the current process.
78 * \param[in] symbol_name Name of symbol to retrieve.
79 * \return Pointer to symbol on success, NULL on failure.
80 */
81M_API void *M_module_symbol(M_module_handle_t handle, const char *symbol_name);
82
83
84/*! Unload a module loaded by M_module_load().
85 * \param[in] handle Loaded module handle from M_module_load()
86 */
88
89/*! @} */
90
91__END_DECLS
92
93#endif /* __M_MODULE_H__ */
void M_module_unload(M_module_handle_t handle)
void * M_module_handle_t
Definition: m_module.h:52
M_module_handle_t M_module_load(const char *module_name, char *error, size_t error_size)
void * M_module_symbol(M_module_handle_t handle, const char *symbol_name)