aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/resource.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resource.hpp')
-rw-r--r--src/resource.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/resource.hpp b/src/resource.hpp
new file mode 100644
index 0000000..602541f
--- /dev/null
+++ b/src/resource.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "error.hpp"
+
+#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)};
+ }
+}