-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.cpp
More file actions
59 lines (53 loc) · 1.04 KB
/
Module.cpp
File metadata and controls
59 lines (53 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Module.cpp
*
* Created on: Sept. 28, 2015
* \copyright 2015 DCBlaha. Distributed under the Mozilla Public License 2.0.
*/
#include "Module.h"
#ifdef __linux__
#include <dlfcn.h>
#endif
bool Module::open(char const *fileName)
{
close();
#if(USE_GLIB)
mModule = g_module_open(fileName, G_MODULE_BIND_LAZY);
#else
#ifdef __linux__
mModule = dlopen(fileName, RTLD_LAZY);
#else
mModule = LoadLibraryA(fileName);
#endif
#endif
return (mModule != nullptr);
}
void Module::close()
{
if(mModule)
{
#if(USE_GLIB)
g_module_close(mModule);
#else
#ifdef __linux__
dlclose(mModule);
#else
FreeLibrary(mModule);
#endif
#endif
mModule = nullptr;
}
}
void Module::loadModuleSymbol(const char *symbolName, ModuleProcPtr *symbol) const
{
#if(USE_GLIB)
if(!g_module_symbol(mModule, symbolName, symbol))
{ *symbol = nullptr; }
#else
#ifdef __linux__
*symbol = dlsym(mModule, symbolName);
#else
*symbol = GetProcAddress(mModule, symbolName);
#endif
#endif
}