lokinet/llarp/win32/dll.cpp
Jason Rhinelander 9921dd6c77
Simplify dll loading via static function pointers
- Replaces RAII handling of DLLs with global function pointers.  (We
  don't unload the dll this way, but that seems unnecessary anyway).
- Simplifies code by just needing to call an init function, but not
  needing to pass around an object holding the function pointers.
- Adds a templated dll loader that takes the dll and a list of
  name/pointer pairs to load the dll and set the pointers in one shot.
2022-09-19 20:26:36 -03:00

25 lines
552 B
C++

#include "dll.hpp"
#include <llarp/util/logging.hpp>
#include <llarp/util/str.hpp>
namespace llarp::win32
{
namespace
{
auto cat = log::Cat("win32-dll");
}
namespace detail
{
HMODULE
load_dll(const std::string& dll)
{
auto handle = LoadLibraryExA(dll.c_str(), NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR);
if (not handle)
throw win32::error{fmt::format("failed to load '{}'", dll)};
log::info(cat, "loaded '{}'", dll);
return handle;
}
} // namespace detail
} // namespace llarp::win32