Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
DynamicLibrary.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
20#pragma once
21
22#if defined(_WIN32)
23# ifndef WIN32_LEAN_AND_MEAN
24# define WIN32_LEAN_AND_MEAN
25# endif
26// min/max arrive as MACROS otherwise, and the next numeric_limits<T>::max()
27// in any translation unit that included this reads as ::() -- reported
28// against that line, never against this one.
29# ifndef NOMINMAX
30# define NOMINMAX
31# endif
32# include <windows.h>
33#else
34# include <dlfcn.h>
35#endif
36
37namespace esengine::core {
38
42inline void* openLibrary(const char* path) {
43#if defined(_WIN32)
44 return reinterpret_cast<void*>(::LoadLibraryA(path));
45#else
46 // LOCAL, so a symbol here cannot satisfy an unrelated lookup elsewhere.
47 return ::dlopen(path, RTLD_LAZY | RTLD_LOCAL);
48#endif
49}
50
52inline void closeLibrary(void* handle) {
53 if (handle == nullptr) return;
54#if defined(_WIN32)
55 ::FreeLibrary(reinterpret_cast<HMODULE>(handle));
56#else
57 ::dlclose(handle);
58#endif
59}
60
63inline void* librarySymbol(void* handle, const char* name) {
64 if (handle == nullptr) return nullptr;
65#if defined(_WIN32)
66 return reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(handle), name));
67#else
68 return ::dlsym(handle, name);
69#endif
70}
71
72} // namespace esengine::core
void closeLibrary(void *handle)
void * openLibrary(const char *path)
void * librarySymbol(void *handle, const char *name)