mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
68148e098f
* add unit tests with ability to pretend to be different network setups
32 lines
645 B
C++
32 lines
645 B
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <string>
|
|
#include <windows.h>
|
|
#include <stdexcept>
|
|
|
|
#include <llarp/util/str.hpp>
|
|
|
|
namespace llarp::win32
|
|
{
|
|
namespace
|
|
{
|
|
inline std::string
|
|
error_to_string(DWORD err)
|
|
{
|
|
std::array<CHAR, 512> buffer{};
|
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, &err, 0, 0, buffer.data(), buffer.size(), nullptr);
|
|
return std::string{buffer.data()};
|
|
}
|
|
} // namespace
|
|
|
|
class error : public std::runtime_error
|
|
{
|
|
public:
|
|
error(DWORD err, std::string msg)
|
|
: std::runtime_error{fmt::format("{}: {}", msg, error_to_string(err))}
|
|
{}
|
|
};
|
|
} // namespace llarp::win32
|