36#ifndef WIN32_LEAN_AND_MEAN
37#define WIN32_LEAN_AND_MEAN
75 static const bool promoted = [] {
85 constexpr int kPromoteMode = RTLD_LAZY | RTLD_GLOBAL | RTLD_NOLOAD;
87 constexpr int kPromoteMode = RTLD_GLOBAL | RTLD_NOLOAD;
89 if (
void* self = ::dlopen(info.dli_fname, kPromoteMode)) {
117 : path_(
path), policy_(policy) {
124 if (
this != &other) {
135 bool valid() const noexcept {
return handle_ !=
nullptr; }
136 explicit operator bool() const noexcept {
return valid(); }
138 const std::string&
error() const noexcept {
return error_; }
139 const std::string&
path() const noexcept {
return path_; }
149 if (!handle_ || !name)
return nullptr;
151 return reinterpret_cast<void*
>(
152 ::GetProcAddress(
reinterpret_cast<HMODULE
>(handle_), name));
154 return ::dlsym(handle_, name);
159 template <
typename T>
160 T
symbol(
const char* name)
const noexcept {
168 if (!handle_)
return false;
169 const bool ok = native_close(handle_);
175 void open(
const std::string&
path) {
178 const BOOL changed = ::SetThreadErrorMode(
179 SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX, &old_mode);
180 handle_ =
reinterpret_cast<void*
>(::LoadLibraryA(
path.c_str()));
181 if (changed) ::SetThreadErrorMode(old_mode,
nullptr);
182 if (!handle_) error_ =
"LoadLibraryA failed for '" +
path +
"'";
189 handle_ = ::dlopen(
path.c_str(), RTLD_NOW | RTLD_LOCAL);
191 const char* e = ::dlerror();
192 error_ = e ? e : (
"dlopen failed for '" +
path +
"'");
197 static bool native_close(
void* handle)
noexcept {
199 return ::FreeLibrary(
reinterpret_cast<HMODULE
>(handle)) != 0;
201 return ::dlclose(handle) == 0;
205 void destroy() noexcept {
207 native_close(handle_);
215 handle_ =
other.handle_;
216 path_ = std::move(
other.path_);
217 error_ = std::move(
other.error_);
218 policy_ =
other.policy_;
219 other.handle_ =
nullptr;
222 void* handle_ =
nullptr;
@ other
Definition udev_monitor.hpp:26