Browse Source

Add WindowsUtils class

- add WindowsUtils class to provide some Windows
OS specific helper functionality
Patrick-Christopher Mattulat 3 years ago
parent
commit
ce919cdc18
2 changed files with 43 additions and 0 deletions
  1. 3 0
      include/ls_std/ls_std.hpp
  2. 40 0
      include/ls_std/utils/WindowsUtils.hpp

+ 3 - 0
include/ls_std/ls_std.hpp

@@ -74,6 +74,9 @@
 
 #include "utils/RegexUtils.hpp"
 #include "utils/STLUtils.hpp"
+#if _WIN32
+#include "utils/WindowsUtils.hpp"
+#endif
 
 #include "event/Event.hpp"
 #include "event/EventTypes.hpp"

+ 40 - 0
include/ls_std/utils/WindowsUtils.hpp

@@ -0,0 +1,40 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-12-06
+ * Changed:         2020-12-06
+ *
+ * */
+
+#ifndef LS_STD_WINDOWS_UTILS_HPP
+#define LS_STD_WINDOWS_UTILS_HPP
+
+#include <ls_std/base/Types.hpp>
+#include <string>
+#include <windows.h>
+
+namespace ls_std {
+  class WindowsUtils {
+    public:
+
+      WindowsUtils() = default;
+      ~WindowsUtils() = default;
+
+      static std::string getMessageFromErrorCode(const int& _errorCode) {
+        ls_std::byte messageBuffer[256 + 1];
+
+        FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+                       nullptr,
+                       _errorCode,
+                       MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+                       messageBuffer,
+                       sizeof (messageBuffer),
+                       nullptr);
+
+        return std::string {messageBuffer};
+      }
+  };
+}
+
+#endif