This commit is contained in:
2026-05-03 11:16:56 +10:00
parent f6db9ee3e6
commit ee929374a8
14 changed files with 873 additions and 350 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include <windows.h>
class UniqueHandle
{
public:
explicit UniqueHandle(HANDLE handle = NULL) : mHandle(handle) {}
~UniqueHandle() { reset(); }
UniqueHandle(const UniqueHandle&) = delete;
UniqueHandle& operator=(const UniqueHandle&) = delete;
UniqueHandle(UniqueHandle&& other) noexcept : mHandle(other.release()) {}
UniqueHandle& operator=(UniqueHandle&& other) noexcept
{
if (this != &other)
reset(other.release());
return *this;
}
HANDLE get() const { return mHandle; }
bool valid() const { return mHandle != NULL && mHandle != INVALID_HANDLE_VALUE; }
HANDLE release()
{
HANDLE handle = mHandle;
mHandle = NULL;
return handle;
}
void reset(HANDLE handle = NULL)
{
if (valid())
CloseHandle(mHandle);
mHandle = handle;
}
private:
HANDLE mHandle;
};