4#include "../Logging/Logger.h"
14 std::span<const char*> dllVersions() {
16 static std::array paths = {
".Debug.dll" };
17 return std::span<const char*>(paths);
18#elif defined( OSOMP_EnableProfiler )
19 static std::array paths = {
".ReleaseMemProfile.dll",
".Release.dll" };
20 return std::span<const char*>(paths);
22 static std::array paths = {
".ReleaseASan.dll",
".Release.dll" };
23 return std::span<const char*>(paths);
25 static std::array paths = {
".Release.dll" };
26 return std::span<const char*>(paths);
42 std::string fullPath = path;
44 if (fullPath.find(
".dll") == std::string::npos) {
51 std::span<const char*> versions = dllVersions();
52 std::string libraryPath;
53 libraryPath.reserve(fullPath.size() + 40);
54 for (
const char* version : versions) {
56 libraryPath += fullPath;
57 libraryPath += version;
58 handle = LoadLibraryW(Cogs::widen(libraryPath).c_str());
62 fullPath = libraryPath;
66 handle = LoadLibraryW(Cogs::widen(path).c_str());
70 DWORD error = GetLastError();
71 LPWSTR messageBuffer =
nullptr;
72 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
75 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
76 reinterpret_cast<LPWSTR
>(&messageBuffer),
79 std::string message = narrow(messageBuffer);
80 LocalFree(messageBuffer);
81 while (!message.empty() && (message.back() ==
'\r' || message.back() ==
'\n')) { message.pop_back(); }
82 LOG_ERROR(logger,
"Failed to load %s: Error %#x: %s", fullPath.c_str(), GetLastError(), message.c_str());
85 status = handle ? LoadStatus::Loaded : LoadStatus::Failed;
88void Cogs::Module::unload(
void* handle) {
90 FreeLibrary(
static_cast<HMODULE
>(handle));
100void* Cogs::Module::getProcAddress(
void* handle,
const char* procName) {
101 return GetProcAddress(
static_cast<HMODULE
>(handle), procName);
Log implementation class.
static void load(const std::string &path, LoadStatus &status, void *&handle)
Attempts to load a shared library with the given name.
constexpr Log getLogger(const char(&name)[LEN]) noexcept