ReactOS  0.4.11-dev-946-g431643b
cmdHelpMsg.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS net command
4  * FILE: base/applications/network/net/cmdHelpMsg.c
5  * PURPOSE:
6  *
7  * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
8  */
9 
10 #include "net.h"
11 
12 #include <stdlib.h>
13 
15 {
16  WCHAR szBuffer[MAX_PATH];
17  HMODULE hMsgDll = NULL;
18  INT i;
19  LONG errNum;
20  PWSTR endptr;
21  PWSTR pBuffer;
22  PWSTR pInserts[10] = {L"***", L"***", L"***", L"***",
23  L"***", L"***", L"***", L"***",
24  L"***", NULL};
25 
26  if (argc < 3)
27  {
30  return 1;
31  }
32 
33  for (i = 2; i < argc; i++)
34  {
35  if (_wcsicmp(argv[i], L"/help") == 0)
36  {
41  return 1;
42  }
43  }
44 
45  errNum = wcstol(argv[2], &endptr, 10);
46  if (*endptr != 0)
47  {
50  return 1;
51  }
52 
53  if (errNum >= MIN_LANMAN_MESSAGE_ID && errNum <= MAX_LANMAN_MESSAGE_ID)
54  {
55  /* Load netmsg.dll */
56  GetSystemDirectoryW(szBuffer, ARRAYSIZE(szBuffer));
57  wcscat(szBuffer, L"\\netmsg.dll");
58 
59  hMsgDll = LoadLibrary(szBuffer);
60  if (hMsgDll == NULL)
61  {
62  ConPrintf(StdOut, L"Failed to load netmsg.dll\n");
63  return 0;
64  }
65 
68  hMsgDll,
69  errNum,
71  (LPWSTR)&pBuffer,
72  0,
73  (va_list *)pInserts);
74  if (pBuffer)
75  {
76  ConPrintf(StdOut, L"\n%s\n", pBuffer);
77  LocalFree(pBuffer);
78  }
79  else
80  {
81  PrintErrorMessage(3871);
82  }
83 
84  FreeLibrary(hMsgDll);
85  }
86  else
87  {
88  /* Retrieve the message string without appending extra newlines */
91  NULL,
92  errNum,
94  (LPWSTR)&pBuffer,
95  0,
96  (va_list *)pInserts);
97  if (pBuffer)
98  {
99  ConPrintf(StdOut, L"\n%s\n", pBuffer);
100  LocalFree(pBuffer);
101  }
102  else
103  {
104  PrintErrorMessage(3871);
105  }
106  }
107 
108  return 0;
109 }
110 
111 /* EOF */
112 
static int argc
Definition: ServiceArgs.c:12
#define IDS_HELPMSG_HELP_2
Definition: resource.h:44
#define LoadLibrary
Definition: winbase.h:3676
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint16_t * PWSTR
Definition: typedefs.h:54
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
long LONG
Definition: pedump.c:60
#define MIN_LANMAN_MESSAGE_ID
Definition: lmcons.h:10
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
char * va_list
Definition: acmsvcex.h:78
#define IDS_HELPMSG_SYNTAX
Definition: resource.h:42
INT cmdHelpMsg(INT argc, WCHAR **argv)
Definition: cmdHelpMsg.c:14
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define FreeLibrary(x)
Definition: compat.h:405
#define MAX_LANMAN_MESSAGE_ID
Definition: lmcons.h:11
#define MAX_PATH
Definition: compat.h:26
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
#define IDS_HELPMSG_HELP_1
Definition: resource.h:43
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define StdOut
Definition: stream.h:76
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50