Emit Win32 error messages on failure.
authorEmanuele Aliberti <ea@iol.it>
Thu, 11 Aug 2005 09:07:48 +0000 (09:07 +0000)
committerEmanuele Aliberti <ea@iol.it>
Thu, 11 Aug 2005 09:07:48 +0000 (09:07 +0000)
svn path=/trunk/; revision=17281

reactos/subsys/system/sm/En.rc
reactos/subsys/system/sm/resource.h
reactos/subsys/system/sm/sm.c
reactos/subsys/system/sm/sm.xml
reactos/subsys/system/sm/win32err.c [new file with mode: 0644]

index e9f3338..35e6705 100644 (file)
@@ -32,8 +32,6 @@ IDS_shutdown_msg, "shutdown an optional environment subsystem;"
 \r
 IDS_Unknown, "Unknown command '%s'.\n"\r
 \r
-IDS_Status, "Status 0x%08lx\n"\r
-\r
 IDS_SM1,  "SM SubSystem Directory\n\n\\r
 SSID PID      Flags\n\\r
 ---- -------- ------------\n"\r
index 8163092..fbee6a6 100644 (file)
 #define IDS_shutdown_msg                   209
 
 #define IDS_Unknown                        300
-#define IDS_Not_Imp                                               301
+#define IDS_Not_Imp                       301
 #define IDS_ID                             302
 #define IDS_SM2                            303
 #define IDS_SM1                            304
-#define IDS_Status                         305
-#define IDS_Mangers                        306
-#define IDS_USING                          307
-#define IDS_FAILS_MNG                      308
+#define IDS_Mangers                        305
+#define IDS_USING                          306
+#define IDS_FAILS_MNG                      307
 
 
 /* EOF */
index 1238763..5cb8db3 100644 (file)
 
 #include <sm/helper.h>
 
+VOID PrintWin32Error(PWCHAR,DWORD); /* win32err.c */
+
 #define SM_CMD(n) cmd_##n
 #define SM_CMD_DECL(n) int SM_CMD(n)(int argc, char * argv[])
 #define SM_CMD_CALL(n,c,v) SM_CMD(n)((c),(v))
 
 HANDLE hSmApiPort = (HANDLE) 0;
 
+VOID STDCALL PrintStatusError (NTSTATUS Status)
+{
+       DWORD Win32Error = RtlNtStatusToDosError (Status);
+                       
+       PrintWin32Error (L"sm", Win32Error);
+}
+
 typedef struct _SM_CMD_DESCRIPTOR
 {
        TCHAR Name[RC_STRING_MAX_SIZE];
@@ -117,9 +126,7 @@ SM_CMD_DECL(boot)
 #endif
                if (STATUS_SUCCESS != Status)
                {
-                       LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);
-
-                       _tprintf(UsageMessage, Status);
+                       PrintStatusError (Status);
                }
 
        }
@@ -197,8 +204,7 @@ SM_CMD_DECL(info)
                                     & ReturnDataLength);
        if (STATUS_SUCCESS != Status)
        {
-               LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);
-               _tprintf(UsageMessage, Status);
+               PrintStatusError (Status);
                return EXIT_FAILURE;
        }
        switch (argc)
index 34a5fc4..5340cdb 100644 (file)
@@ -6,5 +6,6 @@
        <library>ntdll</library>
        <library>kernel32</library>
        <file>sm.c</file>
+       <file>win32err.c</file>
        <file>sm.rc</file>
 </module>
diff --git a/reactos/subsys/system/sm/win32err.c b/reactos/subsys/system/sm/win32err.c
new file mode 100644 (file)
index 0000000..83dd10a
--- /dev/null
@@ -0,0 +1,70 @@
+/* $Id: win32err.c 16861 2005-07-29 13:46:03Z ea $\r
+ *\r
+ * win32err.c\r
+ *\r
+ * Copyright (c) 1998 Mark Russinovich\r
+ *     Systems Internals\r
+ *     http://www.sysinternals.com/\r
+ *\r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Library General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this software; see the file COPYING.LIB. If\r
+ * not, write to the Free Software Foundation, Inc., 675 Mass Ave,\r
+ * Cambridge, MA 02139, USA.\r
+ *\r
+ * --------------------------------------------------------------------\r
+ *\r
+ * Print a Win32 error.\r
+ *\r
+ * 1999 February (Emanuele Aliberti)\r
+ *     Taken from chkdskx.c and formatx.c by Mark Russinovich\r
+ *     to be used in all sysutils.\r
+ */\r
+#include <windows.h>\r
+#include <stdio.h>\r
+\r
+//----------------------------------------------------------------------\r
+//\r
+// PrintWin32Error\r
+//\r
+// Takes the win32 error code and prints the text version.\r
+//\r
+//----------------------------------------------------------------------\r
+void\r
+PrintWin32Error(\r
+       PWCHAR  Message,\r
+       DWORD   ErrorCode\r
+       )\r
+{\r
+       PVOID lpMsgBuf;\r
+\r
+       FormatMessageW(\r
+               (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM),\r
+               NULL,\r
+               ErrorCode,\r
+               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),\r
+               (LPWSTR)& lpMsgBuf,\r
+               0,\r
+               NULL\r
+               );\r
+       wprintf(\r
+               L"%s: %s\n",\r
+               Message,\r
+               lpMsgBuf\r
+               );\r
+       LocalFree( lpMsgBuf );\r
+}\r
+\r
+\r
+/* EOF */\r