// core/WinApi.h
#pragma once
#include <windows.h>
#include <tlhelp32.h>
#include <memory>
#include <utility> // for std::forward

namespace WinApi
{
    struct HandleDeleter 
    { 
        void operator()(HANDLE h) const noexcept 
        { 
            if (h && h != INVALID_HANDLE_VALUE) CloseHandle(h); 
        } 
    };

    using UniqueHandle = std::unique_ptr<std::remove_pointer<HANDLE>::type, HandleDeleter>;

    template <typename F>
    struct ScopeExit
    {
        F func;
        explicit ScopeExit(F&& f) noexcept : func(std::forward<F>(f)) {}
        ~ScopeExit() noexcept { func(); }
    };
}