diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp')
-rw-r--r-- | other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp b/other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp new file mode 100644 index 0000000000..6434ec2f7d --- /dev/null +++ b/other-licenses/7zstub/src/CPP/Windows/ErrorMsg.cpp @@ -0,0 +1,66 @@ +// Windows/ErrorMsg.h
+
+#include "StdAfx.h"
+
+#ifndef _UNICODE
+#include "../Common/StringConvert.h"
+#endif
+
+#include "ErrorMsg.h"
+
+#ifndef _UNICODE
+extern bool g_IsNT;
+#endif
+
+namespace NWindows {
+namespace NError {
+
+static bool MyFormatMessage(DWORD errorCode, UString &message)
+{
+ LPVOID msgBuf;
+ #ifndef _UNICODE
+ if (!g_IsNT)
+ {
+ if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, errorCode, 0, (LPTSTR) &msgBuf, 0, NULL) == 0)
+ return false;
+ message = GetUnicodeString((LPCTSTR)msgBuf);
+ }
+ else
+ #endif
+ {
+ if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, errorCode, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)
+ return false;
+ message = (LPCWSTR)msgBuf;
+ }
+ ::LocalFree(msgBuf);
+ return true;
+}
+
+UString MyFormatMessage(DWORD errorCode)
+{
+ UString m;
+ if (!MyFormatMessage(errorCode, m) || m.IsEmpty())
+ {
+ char s[16];
+ for (int i = 0; i < 8; i++)
+ {
+ unsigned t = errorCode & 0xF;
+ errorCode >>= 4;
+ s[7 - i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
+ }
+ s[8] = 0;
+ m += "Error #";
+ m += s;
+ }
+ else if (m.Len() >= 2
+ && m[m.Len() - 1] == 0x0A
+ && m[m.Len() - 2] == 0x0D)
+ m.DeleteFrom(m.Len() - 2);
+ return m;
+}
+
+}}
|