shared_library_WIN.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <mutex>
3 #include <Windows.h>
6 
7 namespace BT
8 {
10 {
11  _handle = nullptr;
12 }
13 
14 void SharedLibrary::load(const std::string& path, int)
15 {
16  std::unique_lock<std::mutex> lock(_mutex);
17 
18  _handle = LoadLibrary(path.c_str());
19  if (!_handle)
20  {
21  throw RuntimeError("Could not load library: " + path);
22  }
23  _path = path;
24 }
25 
27 {
28  std::unique_lock<std::mutex> lock(_mutex);
29 
30  if (_handle)
31  {
32  FreeLibrary((HMODULE)_handle);
33  _handle = 0;
34  }
35  _path.clear();
36 }
37 
38 bool SharedLibrary::isLoaded() const
39 {
40  return _handle != nullptr;
41 }
42 
43 void* SharedLibrary::findSymbol(const std::string& name)
44 {
45  std::unique_lock<std::mutex> lock(_mutex);
46 
47  if (_handle)
48  {
49 #if defined(_WIN32_WCE)
50  std::wstring uname;
51  UnicodeConverter::toUTF16(name, uname);
52  return (void*)GetProcAddressW((HMODULE)_handle, uname.c_str());
53 #else
54  return (void*)GetProcAddress((HMODULE)_handle, name.c_str());
55 #endif
56  }
57 
58  return 0;
59 }
60 
61 const std::string& SharedLibrary::getPath() const
62 {
63  return _path;
64 }
65 
66 std::string SharedLibrary::prefix()
67 {
68  return "";
69 }
70 
71 std::string SharedLibrary::suffix()
72 {
73 #if defined(_DEBUG)
74  return "d.dll";
75 #else
76  return ".dll";
77 #endif
78 }
79 
80 } // namespace BT
static std::string prefix()
static std::string suffix()
const std::string & getPath() const
Simple class for manipulating paths on Linux/Windows/Mac OS.
Definition: path.h:42
void load(const std::string &path, int flags=0)
bool isLoaded() const
Unloads a shared library.
void * findSymbol(const std::string &name)


behaviotree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Tue May 4 2021 02:56:25