Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Windows
using HWND = HWND__*;
using HMONITOR = HMONITOR__*;
using RECT = tagRECT;
using HMODULE = HINSTANCE;

using EXCEPTION_POINTERS = _EXCEPTION_POINTERS;

Expand Down
29 changes: 29 additions & 0 deletions Engine/Source/Runtime/Platform/Private/Platform/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ DEFINE_LOG_CHANNEL(Platform, All)

FSystemInfo FPlatform::SystemInfo = {};

bool8 FDynamicModuleHandle::IsValid() const noexcept
{
return Module != nullptr;
}

void FPlatform::Initialize()
{
DetectOperatingSystem();
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions Engine/Source/Runtime/Platform/Public/Platform/Platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "CPUDetection.hpp"

#include "Window/Window.hpp"

enum class PLATFORM_API EWindowsVersion : uint8
{
Unknown = 0,
Expand All @@ -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:
Expand All @@ -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;

Expand Down
Loading