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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* pdynlib.c
*
*/
#include "pdynlib.h"
#ifdef _WIN32
#include "windows.h"
#else
#include <dlfcn.h>
#endif
pdynlib::pdynlib(const pstring libname)
: m_isLoaded(false), m_lib(nullptr)
{
#ifdef _WIN32
//fprintf(stderr, "win: loading <%s>\n", libname.cstr());
if (libname != "")
m_lib = LoadLibrary(libname.cstr());
else
m_lib = GetModuleHandle(nullptr);
if (m_lib != nullptr)
m_isLoaded = true;
//else
// fprintf(stderr, "win: library <%s> not found!\n", libname.cstr());
#else
//printf("loading <%s>\n", libname.cstr());
if (libname != "")
m_lib = dlopen(libname.cstr(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
if (m_lib != nullptr)
m_isLoaded = true;
//else
// printf("library <%s> not found!\n", libname.cstr());
#endif
}
pdynlib::pdynlib(const pstring path, const pstring libname)
: m_isLoaded(false), m_lib(nullptr)
{
// printf("win: loading <%s>\n", libname.cstr());
#ifdef _WIN32
if (libname != "")
m_lib = LoadLibrary(libname.cstr());
else
m_lib = GetModuleHandle(nullptr);
if (m_lib != nullptr)
m_isLoaded = true;
else
{
//printf("win: library <%s> not found!\n", libname.cstr());
}
#else
//printf("loading <%s>\n", libname.cstr());
if (libname != "")
m_lib = dlopen(libname.cstr(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
if (m_lib != nullptr)
m_isLoaded = true;
else
{
//printf("library <%s> not found!\n", libname.cstr());
}
#endif
}
pdynlib::~pdynlib()
{
if (m_lib != nullptr)
{
#ifdef _WIN32
#else
dlclose(m_lib);
#endif
}
}
bool pdynlib::isLoaded() const
{
return m_isLoaded;
}
void *pdynlib::getsym_p(const pstring name)
{
#ifdef _WIN32
return (void *) GetProcAddress((HMODULE) m_lib, name.cstr());
#else
return dlsym(m_lib, name.cstr());
#endif
}
|