[NET] NET HELPMSG: Add support for network message from netmsg.dll.

This commit is contained in:
Eric Kohl 2018-12-01 17:11:51 +01:00
parent 04f35dc8f5
commit 17fa384a25

View file

@ -13,11 +13,12 @@
INT cmdHelpMsg(INT argc, WCHAR **argv) INT cmdHelpMsg(INT argc, WCHAR **argv)
{ {
WCHAR szBuffer[MAX_PATH];
HMODULE hMsgDll = NULL;
INT i; INT i;
LONG errNum; LONG errNum;
LPWSTR endptr; LPWSTR endptr;
// DWORD dwLength = 0; LPWSTR pBuffer;
LPWSTR lpBuffer;
if (argc < 3) if (argc < 3)
{ {
@ -46,23 +47,51 @@ INT cmdHelpMsg(INT argc, WCHAR **argv)
return 1; return 1;
} }
/* Retrieve the message string without appending extra newlines */ if (errNum >= MIN_LANMAN_MESSAGE_ID && errNum <= MAX_LANMAN_MESSAGE_ID)
// dwLength =
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
errNum,
LANG_USER_DEFAULT,
(LPWSTR)&lpBuffer,
0, NULL);
if (lpBuffer /* && dwLength */)
{ {
ConPrintf(StdOut, L"\n%s\n", lpBuffer); /* Load netmsg.dll */
LocalFree(lpBuffer); GetSystemDirectoryW(szBuffer, ARRAYSIZE(szBuffer));
wcscat(szBuffer, L"\\netmsg.dll");
hMsgDll = LoadLibrary(szBuffer);
if (hMsgDll == NULL)
{
ConPrintf(StdOut, L"Failed to load netmsg.dll\n");
return 0;
}
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_IGNORE_INSERTS,
hMsgDll,
errNum,
LANG_USER_DEFAULT,
(LPWSTR)&pBuffer,
0,
NULL);
if (pBuffer)
{
ConPrintf(StdOut, L"\n%s\n", pBuffer);
LocalFree(pBuffer);
}
FreeLibrary(hMsgDll);
} }
else else
{ {
ConPrintf(StdOut, L"Unrecognized error code: %ld\n", errNum); /* Retrieve the message string without appending extra newlines */
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errNum,
LANG_USER_DEFAULT,
(LPWSTR)&pBuffer,
0,
NULL);
if (pBuffer)
{
ConPrintf(StdOut, L"\n%s\n", pBuffer);
LocalFree(pBuffer);
}
} }
return 0; return 0;