https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f5bd2c1f8da0f83d33e9c…
commit f5bd2c1f8da0f83d33e9ca17435c96602d08787e
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sat Dec 1 22:03:17 2018 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sat Dec 1 22:06:30 2018 +0100
[NET] NET HLPMSG: Fill inserts with '***' and print a proper error message if
the desired message could not be found.
---
base/applications/network/net/cmdHelpMsg.c | 23 ++++++---
base/applications/network/net/main.c | 83 ++++++++++++++++++++++++++++++
base/applications/network/net/net.h | 4 ++
3 files changed, 104 insertions(+), 6 deletions(-)
diff --git a/base/applications/network/net/cmdHelpMsg.c
b/base/applications/network/net/cmdHelpMsg.c
index cbe1ffe99d..801def5cce 100644
--- a/base/applications/network/net/cmdHelpMsg.c
+++ b/base/applications/network/net/cmdHelpMsg.c
@@ -17,8 +17,11 @@ INT cmdHelpMsg(INT argc, WCHAR **argv)
HMODULE hMsgDll = NULL;
INT i;
LONG errNum;
- LPWSTR endptr;
- LPWSTR pBuffer;
+ PWSTR endptr;
+ PWSTR pBuffer;
+ PWSTR pInserts[10] = {L"***", L"***", L"***",
L"***",
+ L"***", L"***", L"***",
L"***",
+ L"***", NULL};
if (argc < 3)
{
@@ -61,18 +64,22 @@ INT cmdHelpMsg(INT argc, WCHAR **argv)
}
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
- FORMAT_MESSAGE_IGNORE_INSERTS,
+ FORMAT_MESSAGE_ARGUMENT_ARRAY,
hMsgDll,
errNum,
LANG_USER_DEFAULT,
(LPWSTR)&pBuffer,
0,
- NULL);
+ (va_list *)pInserts);
if (pBuffer)
{
ConPrintf(StdOut, L"\n%s\n", pBuffer);
LocalFree(pBuffer);
}
+ else
+ {
+ PrintErrorMessage(3871);
+ }
FreeLibrary(hMsgDll);
}
@@ -80,18 +87,22 @@ INT cmdHelpMsg(INT argc, WCHAR **argv)
{
/* Retrieve the message string without appending extra newlines */
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
+ FORMAT_MESSAGE_ARGUMENT_ARRAY,
NULL,
errNum,
LANG_USER_DEFAULT,
(LPWSTR)&pBuffer,
0,
- NULL);
+ (va_list *)pInserts);
if (pBuffer)
{
ConPrintf(StdOut, L"\n%s\n", pBuffer);
LocalFree(pBuffer);
}
+ else
+ {
+ PrintErrorMessage(3871);
+ }
}
return 0;
diff --git a/base/applications/network/net/main.c b/base/applications/network/net/main.c
index 298b875caf..0c932a23f3 100644
--- a/base/applications/network/net/main.c
+++ b/base/applications/network/net/main.c
@@ -76,6 +76,89 @@ PrintPadding(
}
+VOID
+PrintErrorMessage(
+ DWORD dwError)
+{
+ WCHAR szDllBuffer[MAX_PATH];
+ WCHAR szErrorBuffer[16];
+ HMODULE hMsgDll = NULL;
+ PWSTR pBuffer;
+ PWSTR pErrorInserts[2] = {NULL, NULL};
+
+ /* Load netmsg.dll */
+ GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
+ wcscat(szDllBuffer, L"\\netmsg.dll");
+
+ hMsgDll = LoadLibrary(szDllBuffer);
+ if (hMsgDll == NULL)
+ {
+ ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
+ return;
+ }
+
+ if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <=
MAX_LANMAN_MESSAGE_ID)
+ {
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ hMsgDll,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&pBuffer,
+ 0,
+ NULL);
+ if (pBuffer)
+ {
+ ConPrintf(StdErr, L"%s\n", pBuffer);
+ LocalFree(pBuffer);
+ pBuffer = NULL;
+ }
+ }
+ else
+ {
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&pBuffer,
+ 0,
+ NULL);
+ if (pBuffer)
+ {
+ ConPrintf(StdErr, L"%s\n", pBuffer);
+ LocalFree(pBuffer);
+ pBuffer = NULL;
+ }
+ }
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* Format insert for the 3514 message */
+ swprintf(szErrorBuffer, L"%lu", dwError);
+ pErrorInserts[0] = szErrorBuffer;
+
+ /* Format and print the 3514 message */
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
+ FORMAT_MESSAGE_ARGUMENT_ARRAY,
+ hMsgDll,
+ 3514,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&pBuffer,
+ 0,
+ (va_list *)pErrorInserts);
+ if (pBuffer)
+ {
+ ConPrintf(StdErr, L"%s\n", pBuffer);
+ LocalFree(pBuffer);
+ pBuffer = NULL;
+ }
+ }
+
+ FreeLibrary(hMsgDll);
+}
+
+
VOID
ReadFromConsole(
LPWSTR lpInput,
diff --git a/base/applications/network/net/net.h b/base/applications/network/net/net.h
index 3f04b18502..e075a55a6e 100644
--- a/base/applications/network/net/net.h
+++ b/base/applications/network/net/net.h
@@ -36,6 +36,10 @@ PrintPadding(
WCHAR chr,
INT nPaddedLength);
+VOID
+PrintErrorMessage(
+ DWORD dwError);
+
VOID
ReadFromConsole(
LPWSTR lpInput,