ReXGlue SDK
Loading...
Searching...
No Matches
dynlib.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <cstdint>
13#include <filesystem>
14#include <span>
15#include <string>
16#include <string_view>
17
18#include <rex/platform.h>
19#include <rex/types.h>
20#include <rex/utility.h>
21
22namespace rex::platform {
23
24enum class SymbolResolution : u8 {
27};
28
30class REX_API DynamicLibrary : public rex::MoveOnly {
31 public:
32 DynamicLibrary() = default;
33 ~DynamicLibrary();
34
35 DynamicLibrary(DynamicLibrary&& other) noexcept;
36 DynamicLibrary& operator=(DynamicLibrary&& other) noexcept;
37
44 bool Load(const std::filesystem::path& path, SymbolResolution mode = SymbolResolution::kLazy);
45
50 bool LoadNamed(std::string_view name, SymbolResolution mode = SymbolResolution::kLazy);
51
58 bool Attach(const std::filesystem::path& path);
59
61 void Close();
62
63 explicit operator bool() const { return handle_ != nullptr; }
64
69 void* GetRawSymbol(const char* name) const;
70
76 template <typename T>
77 T GetSymbol(const char* name) const {
78 return reinterpret_cast<T>(GetRawSymbol(name));
79 }
80
82 const std::string& GetLastError() const { return last_error_; }
83
84 private:
85 void* handle_ = nullptr;
86 std::string last_error_;
87};
88
89#if REX_PLATFORM_WIN32
96REX_API std::span<const u8> FindImageSection(const void* image, std::string_view name);
97#endif
98
99} // namespace rex::platform
Definition utility.h:28
bool Attach(const std::filesystem::path &path)
void * GetRawSymbol(const char *name) const
const std::string & GetLastError() const
Definition dynlib.h:82
T GetSymbol(const char *name) const
Definition dynlib.h:77
bool LoadNamed(std::string_view name, SymbolResolution mode=SymbolResolution::kLazy)
bool Load(const std::filesystem::path &path, SymbolResolution mode=SymbolResolution::kLazy)
Definition platform.h:345
SymbolResolution
Definition dynlib.h:24
@ kImmediate
Definition dynlib.h:26
@ kLazy
Definition dynlib.h:25
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.