-
Notifications
You must be signed in to change notification settings - Fork 1
/
dl.cpp
39 lines (31 loc) · 887 Bytes
/
dl.cpp
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
#include <nall/dl.hpp>
namespace nall {
#if defined(PLATFORM_WINDOWS)
NALL_HEADER_INLINE auto library::open(const string& name, const string& path) -> bool {
if(handle) close();
if(path) {
string filepath = {path, name, ".dll"};
handle = (uintptr)LoadLibraryW(utf16_t(filepath));
}
if(!handle) {
string filepath = {name, ".dll"};
handle = (uintptr)LoadLibraryW(utf16_t(filepath));
}
return handle;
}
NALL_HEADER_INLINE auto library::openAbsolute(const string& name) -> bool {
if(handle) close();
handle = (uintptr)LoadLibraryW(utf16_t(name));
return handle;
}
NALL_HEADER_INLINE auto library::sym(const string& name) -> void* {
if(!handle) return nullptr;
return (void*)GetProcAddress((HMODULE)handle, name);
}
NALL_HEADER_INLINE auto library::close() -> void {
if(!handle) return;
FreeLibrary((HMODULE)handle);
handle = 0;
}
#endif
}