[NET] NET HLPMSG: Fill inserts with '***' and print a proper error message if the...
authorEric Kohl <eric.kohl@reactos.org>
Sat, 1 Dec 2018 21:03:17 +0000 (22:03 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 1 Dec 2018 21:06:30 +0000 (22:06 +0100)
base/applications/network/net/cmdHelpMsg.c
base/applications/network/net/main.c
base/applications/network/net/net.h

index cbe1ffe..801def5 100644 (file)
@@ -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;
index 298b875..0c932a2 100644 (file)
@@ -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,
index 3f04b18..e075a55 100644 (file)
@@ -36,6 +36,10 @@ PrintPadding(
     WCHAR chr,
     INT nPaddedLength);
 
+VOID
+PrintErrorMessage(
+    DWORD dwError);
+
 VOID
 ReadFromConsole(
     LPWSTR lpInput,