Author: hbelusca
Date: Sat Oct 8 14:48:18 2016
New Revision: 72943
URL:
http://svn.reactos.org/svn/reactos?rev=72943&view=rev
Log:
[PING]
- Use a dynamic-allocated buffer with FormatMessageW, fixes messages disappearance (eg.
ping help in russian). CORE-12108 #comment Fixed in r72943.
- Remove the unneeded 1-line function "Usage" and instead just directly call the
corresponding PrintString function.
Modified:
trunk/reactos/base/applications/network/ping/ping.c
Modified: trunk/reactos/base/applications/network/ping/ping.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] Sat Oct 8 14:48:18
2016
@@ -49,7 +49,6 @@
static BOOL ParseCmdLine(int argc, PWSTR argv[]);
static BOOL ResolveTarget(PCWSTR target);
-static void Usage(void);
static void Ping(void);
static void PrintStats(void);
static BOOL WINAPI ConsoleCtrlHandler(DWORD ControlType);
@@ -180,44 +179,35 @@
void
PrintString(UINT id, ...)
{
- WCHAR Format[1024];
- WCHAR Msg[1024];
- DWORD Len, written;
+#define RC_STRING_MAX_SIZE 4096
+
+ WCHAR Format[RC_STRING_MAX_SIZE];
+ LPWSTR lpMsgBuf = NULL;
+ DWORD Len;
va_list args;
if (!LoadStringW(GetModuleHandleW(NULL), id, Format, _countof(Format)))
{
DPRINT("LoadStringW failed: %lu\n", GetLastError());
-
return;
}
va_start(args, id);
- Len = FormatMessageW(
- FORMAT_MESSAGE_FROM_STRING,
- Format, 0, 0,
- Msg, 1024, &args);
-
- if (Len == 0)
+ Len = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
+ Format, 0, 0, (PWSTR)&lpMsgBuf, 0, &args);
+ if (lpMsgBuf /* && Len != 0 */)
+ {
+ // TODO: Handle writing to file. Well, use the ConUtils lib!
+ WriteConsoleW(hStdOut, lpMsgBuf, Len, &Len, NULL);
+ LocalFree(lpMsgBuf);
+ }
+ else
{
DPRINT("FormatMessageW failed: %lu\n", GetLastError());
-
- va_end(args);
- return;
- }
-
- // TODO: Handle writing to file.
- WriteConsole(hStdOut, Msg, Len, &written, NULL);
+ }
va_end(args);
-}
-
-static
-void
-Usage(void)
-{
- PrintString(IDS_USAGE);
}
static
@@ -228,8 +218,7 @@
if (argc < 2)
{
- Usage();
-
+ PrintString(IDS_USAGE);
return FALSE;
}
@@ -404,14 +393,12 @@
break;
case L'?':
- Usage();
-
+ PrintString(IDS_USAGE);
return FALSE;
default:
PrintString(IDS_BAD_OPTION, argv[i]);
- Usage();
-
+ PrintString(IDS_USAGE);
return FALSE;
}
}