aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.cpp35
-rw-r--r--src/error.hpp23
-rw-r--r--src/os.cpp24
-rw-r--r--src/os.hpp12
-rw-r--r--src/process.hpp9
-rw-r--r--src/resource.cpp37
-rw-r--r--src/resource.hpp21
7 files changed, 58 insertions, 103 deletions
diff --git a/src/error.cpp b/src/error.cpp
deleted file mode 100644
index edce89f..0000000
--- a/src/error.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
-// This file is part of the "Privilege check" project.
-// For details, see https://github.com/egor-tensin/privilege-check.
-// Distributed under the MIT License.
-
-#include "error.hpp"
-
-#include <Windows.h>
-
-#include <exception>
-#include <system_error>
-
-namespace error
-{
- Error make(const char* function_name)
- {
- const auto ec = GetLastError();
- return {static_cast<int>(ec), std::system_category(), function_name};
- }
-
- void raise(const char* function_name)
- {
- throw make(function_name);
- }
-
- void report(const std::exception& e)
- {
- MessageBoxA(NULL, e.what(), NULL, MB_OK);
- }
-
- int get_code(const Error& e)
- {
- return e.code().value();
- }
-}
diff --git a/src/error.hpp b/src/error.hpp
index b8ba468..40522bb 100644
--- a/src/error.hpp
+++ b/src/error.hpp
@@ -5,6 +5,8 @@
#pragma once
+#include <Windows.h>
+
#include <exception>
#include <system_error>
@@ -12,11 +14,24 @@ typedef std::system_error Error;
namespace error
{
- Error make(const char* function_name);
+ inline Error make(const char* function_name)
+ {
+ const auto ec = GetLastError();
+ return {static_cast<int>(ec), std::system_category(), function_name};
+ }
- void raise(const char* function_name);
+ inline void raise(const char* function_name)
+ {
+ throw make(function_name);
+ }
- void report(const std::exception&);
+ inline void report(const std::exception& e)
+ {
+ MessageBoxA(NULL, e.what(), NULL, MB_OK);
+ }
- int get_code(const Error&);
+ inline int get_code(const Error& e)
+ {
+ return e.code().value();
+ }
}
diff --git a/src/os.cpp b/src/os.cpp
deleted file mode 100644
index 13fd766..0000000
--- a/src/os.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
-// This file is part of the "Privilege check" project.
-// For details, see https://github.com/egor-tensin/privilege-check.
-// Distributed under the MIT License.
-
-#include "error.hpp"
-#include "os.hpp"
-
-#include <Windows.h>
-
-namespace os
-{
- OSVERSIONINFOW get_version_info()
- {
- OSVERSIONINFOW info;
- ZeroMemory(&info, sizeof(info));
- info.dwOSVersionInfoSize = sizeof(info);
-
- if (!GetVersionExW(&info))
- error::raise("GetVersionExW");
-
- return info;
- }
-}
diff --git a/src/os.hpp b/src/os.hpp
index c9a89a1..6734fb4 100644
--- a/src/os.hpp
+++ b/src/os.hpp
@@ -11,7 +11,17 @@
namespace os
{
- OSVERSIONINFOW get_version_info();
+ inline OSVERSIONINFOW get_version_info()
+ {
+ OSVERSIONINFOW info;
+ ZeroMemory(&info, sizeof(info));
+ info.dwOSVersionInfoSize = sizeof(info);
+
+ if (!GetVersionExW(&info))
+ error::raise("GetVersionExW");
+
+ return info;
+ }
inline bool is_vista_or_later(const OSVERSIONINFOW& info)
{
diff --git a/src/process.hpp b/src/process.hpp
index c422aac..53fcdf8 100644
--- a/src/process.hpp
+++ b/src/process.hpp
@@ -5,6 +5,7 @@
#pragma once
+#include "error.hpp"
#include "cmd_line.hpp"
#include <Windows.h>
@@ -13,6 +14,14 @@
namespace process
{
+ inline HMODULE load_exe_module()
+ {
+ const auto module = GetModuleHandle(NULL);
+ if (module == NULL)
+ error::raise("GetModuleHandle");
+ return module;
+ }
+
std::wstring get_executable_path();
inline std::wstring get_command_line()
diff --git a/src/resource.cpp b/src/resource.cpp
deleted file mode 100644
index e8ac300..0000000
--- a/src/resource.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
-// This file is part of the "Privilege check" project.
-// For details, see https://github.com/egor-tensin/privilege-check.
-// Distributed under the MIT License.
-
-#include "error.hpp"
-#include "resource.hpp"
-
-#include <Windows.h>
-
-#include <cstddef>
-
-#include <string>
-
-namespace resource
-{
- HMODULE load_exe_module()
- {
- const auto module = GetModuleHandle(NULL);
- if (module == NULL)
- error::raise("GetModuleHandle");
- return module;
- }
-
- std::wstring load_string(unsigned int id)
- {
- wchar_t* s = nullptr;
-
- const auto ret = LoadStringW(
- load_exe_module(), id, reinterpret_cast<wchar_t*>(&s), 0);
-
- if (ret <= 0)
- error::raise("LoadStringW");
-
- return {s, static_cast<std::size_t>(ret)};
- }
-}
diff --git a/src/resource.hpp b/src/resource.hpp
index 0e3186c..a0f1cc3 100644
--- a/src/resource.hpp
+++ b/src/resource.hpp
@@ -5,13 +5,30 @@
#pragma once
+#include "error.hpp"
+#include "process.hpp"
+
#include <Windows.h>
+#include <cstddef>
+
#include <string>
namespace resource
{
- HMODULE load_exe_module();
+ inline std::wstring load_string(unsigned int id)
+ {
+ wchar_t* s = nullptr;
+
+ const auto ret = LoadStringW(
+ process::load_exe_module(),
+ id,
+ reinterpret_cast<wchar_t*>(&s),
+ 0);
+
+ if (ret <= 0)
+ error::raise("LoadStringW");
- std::wstring load_string(unsigned int id);
+ return {s, static_cast<std::size_t>(ret)};
+ }
}