-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDynamicModuleLoader.h
80 lines (58 loc) · 1.44 KB
/
DynamicModuleLoader.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//!
//! @brief - Load dynamic libraries on Windows and Linux platforms
//!
//! @author - HuangWang
//!
//! @data - 2019-09-26
//!
#ifndef _DYNAMIC_MODULE_LOADER_H_
#define _DYNAMIC_MODULE_LOADER_H_
#include <string>
#include <fstream>
#define _DYNAMIC_LOAD
#define WINDOWS
#if defined(_DYNAMIC_LOAD)
#if defined(WINDOWS)
#include <Windows.h>
#define MODULE_HANDLER HINSTANCE
#elif defined(LINUX)
#include <dlfcn.h>
#define MODULE_HANDLER void*
#endif
#endif
#ifdef WINDOWS
#define PLATFORM_PATH_SPLIT_CHAR "\\"
#define PLATFORM_DYNAMIC_LIBRARY_PRE ""
#define PLATFORM_DYNAMIC_LIBRARY_EXT ".dll"
#elif defined (LINUX)
#define PLATFORM_PATH_SPLIT_CHAR "/"
#define PLATFORM_DYNAMIC_LIBRARY_PRE "lib"
#define PLATFORM_DYNAMIC_LIBRARY_EXT ".so"
#endif // WINDOWS
namespace DynamicModuleLoaderSpace
{
enum DynamicModuleState
{
DMS_UnLoaded = 0,
DMS_Loaded = 1
};
class DynamicModuleLoader
{
public:
DynamicModuleLoader();
virtual ~DynamicModuleLoader();
static bool IsFileExist(const std::string filePath);
bool LoadDynamicModule(const std::string dynamicModulePath);
void* GetFunction(const std::string functionName);
bool UnloadDynamicModule();
std::string GetErrorMessage();
bool GetDynamicModuleState();
private:
void GetInternalErrorMessge(int errorCode);
private:
MODULE_HANDLER m_DynamicModulePtr;
std::string m_ErrorMessage;
DynamicModuleState m_DynamicModuleState;
};
}
#endif /// _DYNAMIC_MODULE_LOADER_H_