diff --git a/Engine/Source/Runtime/Core/Public/Core/Utility/WindowsDefinitions.hpp b/Engine/Source/Runtime/Core/Public/Core/Utility/WindowsDefinitions.hpp index d6168eb..422ebef 100644 --- a/Engine/Source/Runtime/Core/Public/Core/Utility/WindowsDefinitions.hpp +++ b/Engine/Source/Runtime/Core/Public/Core/Utility/WindowsDefinitions.hpp @@ -20,6 +20,7 @@ namespace Windows using HWND = HWND__*; using HMONITOR = HMONITOR__*; using RECT = tagRECT; + using HMODULE = HINSTANCE; using EXCEPTION_POINTERS = _EXCEPTION_POINTERS; diff --git a/Engine/Source/Runtime/Platform/Private/Platform/Platform.cpp b/Engine/Source/Runtime/Platform/Private/Platform/Platform.cpp index ca81763..667db3c 100644 --- a/Engine/Source/Runtime/Platform/Private/Platform/Platform.cpp +++ b/Engine/Source/Runtime/Platform/Private/Platform/Platform.cpp @@ -12,6 +12,11 @@ DEFINE_LOG_CHANNEL(Platform, All) FSystemInfo FPlatform::SystemInfo = {}; +bool8 FDynamicModuleHandle::IsValid() const noexcept +{ + return Module != nullptr; +} + void FPlatform::Initialize() { DetectOperatingSystem(); @@ -56,6 +61,30 @@ bool8 FPlatform::SetEnvVariable(const FString& VariableName, const FString& Valu return SetEnvironmentVariable(VariableName.c_str(), Value.c_str()) != 0; } +FDynamicModuleHandle FPlatform::LoadDynamicModule(const FString& Name) noexcept +{ + const HMODULE Module = LoadLibrary(Name.c_str()); + if (Module == nullptr) + { + CVLOG(LogPlatform, Error, "Failed to load module: {}", Name); + return {}; + } + return {.Module = Module}; +} + +void FPlatform::UnloadDynamicModule(FDynamicModuleHandle&& Module) noexcept +{ + if (!Module.IsValid()) + { + CVLOG(LogPlatform, Warning, "Attempting to unload invalid module"); + return; + } + if (!FreeLibrary(std::move(Module).Module)) + { + CVLOG(LogPlatform, Error, "Failed to unload module"); + } +} + FCPUInfo FPlatform::GetCPUInfo() noexcept { return FCPUDetection::GetCPUInfo(); diff --git a/Engine/Source/Runtime/Platform/Public/Platform/Platform.hpp b/Engine/Source/Runtime/Platform/Public/Platform/Platform.hpp index fec9f7c..086e49a 100644 --- a/Engine/Source/Runtime/Platform/Public/Platform/Platform.hpp +++ b/Engine/Source/Runtime/Platform/Public/Platform/Platform.hpp @@ -4,6 +4,8 @@ #include "CPUDetection.hpp" +#include "Window/Window.hpp" + enum class PLATFORM_API EWindowsVersion : uint8 { Unknown = 0, @@ -20,6 +22,14 @@ struct PLATFORM_API FSystemInfo FString ComputerName; }; +struct PLATFORM_API FDynamicModuleHandle +{ + Windows::HMODULE Module = nullptr; + +public: + [[nodiscard]] bool8 IsValid() const noexcept; +}; + class PLATFORM_API FPlatform { public: @@ -31,6 +41,9 @@ class PLATFORM_API FPlatform [[nodiscard]] static FString GetEnvVariable(const FString& VariableName, const FString& DefaultValue) noexcept; static bool8 SetEnvVariable(const FString& VariableName, const FString& Value) noexcept; + [[nodiscard]] static FDynamicModuleHandle LoadDynamicModule(const FString& Name) noexcept; + static void UnloadDynamicModule(FDynamicModuleHandle&& Module) noexcept; + [[nodiscard]] static FCPUInfo GetCPUInfo() noexcept; [[nodiscard]] static FSystemInfo GetSystemInfo() noexcept;