[NETSTAT] Simplify DoFormatMessage(), and fix build.

This commit is contained in:
Hermès Bélusca-Maïto 2019-06-20 20:59:23 +02:00
parent bd3c852012
commit dda5ec44b0
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -52,31 +52,13 @@ PCWSTR TcpState[] = {
/*
* format message string and display output
*/
DWORD DoFormatMessage(DWORD ErrorCode)
VOID DoFormatMessage(DWORD ErrorCode)
{
LPVOID lpMsgBuf;
DWORD RetVal;
if (dwError == ERROR_SUCCESS)
return;
if ((RetVal = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
(LPWSTR) &lpMsgBuf,
0,
NULL )))
{
wprintf(L"%s", (LPWSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
/* return number of TCHAR's stored in output buffer
* excluding '\0' - as FormatMessage does*/
return RetVal;
}
else
return 0;
ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwError, LANG_USER_DEFAULT);
}
/*
@ -501,8 +483,8 @@ VOID ShowTcpTable()
PID[0] = 0;
}
ConPuts(StdOut, L" %-6s %-22s %-22s %-11s %s\n", L"TCP",
Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
ConPrintf(StdOut, L" %-6s %-22s %-22s %-11s %s\n", L"TCP",
Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
}
}
HeapFree(GetProcessHeap(), 0, tcpTable);
@ -555,7 +537,7 @@ VOID ShowUdpTable()
PID[0] = 0;
}
ConPuts(StdOut, L" %-6s %-22s %-34s %s\n", L"UDP", Host, L"*:*", PID);
ConPrintf(StdOut, L" %-6s %-22s %-34s %s\n", L"UDP", Host, L"*:*", PID);
}
HeapFree(GetProcessHeap(), 0, udpTable);