Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core.native/native_src/win/util.c')
-rw-r--r--core/org.eclipse.cdt.core.native/native_src/win/util.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/util.c b/core/org.eclipse.cdt.core.native/native_src/win/util.c
index 01b1c35521a..13041c39be6 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/util.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/util.c
@@ -151,3 +151,39 @@ int copyTo(wchar_t *target, const wchar_t *source, int cpyLength, int availSpace
return j;
}
+
+wchar_t *formatWinErrorCode(DWORD messageId) {
+ const wchar_t *NULL_STR = L"(null)";
+ size_t size = 0;
+ wchar_t *msg = NULL;
+
+ DWORD langId[] = {
+ MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), // US English
+ MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), // Any English
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // User default language
+ 0 // Let FormatMessage lookup the right language
+ };
+ wchar_t *winBuf = NULL;
+
+ /* Format the message */
+ for (size_t i = 0; i < sizeof(langId) / sizeof(langId[0]); i++) {
+ if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, messageId, langId[i], (wchar_t *)&winBuf, 0, NULL) == 0) {
+ winBuf = NULL;
+ }
+
+ if (winBuf != NULL) {
+ break;
+ }
+ }
+
+ /* Prefix the message */
+ size = 100 + wcslen(winBuf ? winBuf : NULL_STR);
+ msg = (wchar_t *)calloc(size + 1, sizeof(wchar_t));
+ if (msg) {
+ snwprintf(msg, size, L"Code 0x%lx: %s", (unsigned long)messageId, (winBuf ? winBuf : NULL_STR));
+ }
+
+ LocalFree(winBuf);
+ return msg;
+}

Back to the top