forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_library_WIN.cpp
More file actions
82 lines (67 loc) · 1.31 KB
/
shared_library_WIN.cpp
File metadata and controls
82 lines (67 loc) · 1.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "behaviortree_cpp/exceptions.h"
#include "behaviortree_cpp/utils/shared_library.h"
#include <mutex>
#include <string>
#include <Windows.h>
namespace BT
{
SharedLibrary::SharedLibrary()
{
_handle = nullptr;
}
void SharedLibrary::load(const std::string& path, int)
{
std::unique_lock<std::mutex> lock(_mutex);
_handle = LoadLibrary(path.c_str());
if(!_handle)
{
throw RuntimeError("Could not load library: " + path);
}
_path = path;
}
void SharedLibrary::unload()
{
std::unique_lock<std::mutex> lock(_mutex);
if(_handle)
{
FreeLibrary((HMODULE)_handle);
_handle = 0;
}
_path.clear();
}
bool SharedLibrary::isLoaded() const
{
return _handle != nullptr;
}
void* SharedLibrary::findSymbol(const std::string& name)
{
std::unique_lock<std::mutex> lock(_mutex);
if(_handle)
{
#if defined(_WIN32_WCE)
std::wstring uname;
UnicodeConverter::toUTF16(name, uname);
return (void*)GetProcAddressW((HMODULE)_handle, uname.c_str());
#else
return (void*)GetProcAddress((HMODULE)_handle, name.c_str());
#endif
}
return 0;
}
const std::string& SharedLibrary::getPath() const
{
return _path;
}
std::string SharedLibrary::prefix()
{
return "";
}
std::string SharedLibrary::suffix()
{
#if defined(_DEBUG)
return "d.dll";
#else
return ".dll";
#endif
}
} // namespace BT