13void*
open(
const char* file) {
15 if (HMODULE handle = LoadLibraryA(file)) {
16 return static_cast<void*
>(handle);
18 error(
"could not load plugin '{}' due to error '{}'\n"
19 "see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes\n",
20 file, GetLastError());
23 if (
void* handle = dlopen(file, RTLD_NOW))
25 else if (
auto err = dlerror())
26 error(
"could not load plugin '{}' due to error '{}'\n", file, err);
28 error(
"could not load plugin '{}'\n", file);
32void*
get(
void* handle,
const char* symbol) {
34 if (
auto addr = GetProcAddress(
static_cast<HMODULE
>(handle), symbol)) {
35 return reinterpret_cast<void*
>(addr);
37 error(
"could not find symbol '{}' in plugin due to error '{}'\n"
38 "see (https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes)\n",
39 symbol, GetLastError());
43 void* addr = dlsym(handle, symbol);
44 if (
auto err = dlerror())
45 error(
"could not find symbol '{}' in plugin due to error '{}' \n", symbol, err);
53 if (!FreeLibrary(
static_cast<HMODULE
>(handle)))
error(
"FreeLibrary() failed\n");
55 if (
auto err = dlclose(handle))
error(
"dlclose() failed with error code '{}'\n", err);
void * get(void *handle, const char *symbol_name)
void * open(const char *filename)
void error(std::format_string< Args... > fmt, Args &&... args)
Wraps std::format to throw T with a formatted message.