Emit Win32 error messages on failure.
Modified: trunk/reactos/subsys/system/sm/En.rc
Modified: trunk/reactos/subsys/system/sm/resource.h
Modified: trunk/reactos/subsys/system/sm/sm.c
Modified: trunk/reactos/subsys/system/sm/sm.xml
Added: trunk/reactos/subsys/system/sm/win32err.c

Modified: trunk/reactos/subsys/system/sm/En.rc
--- trunk/reactos/subsys/system/sm/En.rc	2005-08-11 09:01:30 UTC (rev 17280)
+++ trunk/reactos/subsys/system/sm/En.rc	2005-08-11 09:07:48 UTC (rev 17281)
@@ -32,8 +32,6 @@
 
 IDS_Unknown, "Unknown command '%s'.\n"
 
-IDS_Status, "Status 0x%08lx\n"
-
 IDS_SM1,  "SM SubSystem Directory\n\n\
 SSID PID      Flags\n\
 ---- -------- ------------\n"

Modified: trunk/reactos/subsys/system/sm/resource.h
--- trunk/reactos/subsys/system/sm/resource.h	2005-08-11 09:01:30 UTC (rev 17280)
+++ trunk/reactos/subsys/system/sm/resource.h	2005-08-11 09:07:48 UTC (rev 17281)
@@ -14,14 +14,13 @@
 #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 */

Modified: trunk/reactos/subsys/system/sm/sm.c
--- trunk/reactos/subsys/system/sm/sm.c	2005-08-11 09:01:30 UTC (rev 17280)
+++ trunk/reactos/subsys/system/sm/sm.c	2005-08-11 09:07:48 UTC (rev 17281)
@@ -35,12 +35,21 @@
 
 #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 @@
 #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 @@
 				     & 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)

Modified: trunk/reactos/subsys/system/sm/sm.xml
--- trunk/reactos/subsys/system/sm/sm.xml	2005-08-11 09:01:30 UTC (rev 17280)
+++ trunk/reactos/subsys/system/sm/sm.xml	2005-08-11 09:07:48 UTC (rev 17281)
@@ -6,5 +6,6 @@
 	<library>ntdll</library>
 	<library>kernel32</library>
 	<file>sm.c</file>
+	<file>win32err.c</file>
 	<file>sm.rc</file>
 </module>

Added: trunk/reactos/subsys/system/sm/win32err.c
--- trunk/reactos/subsys/system/sm/win32err.c	2005-08-11 09:01:30 UTC (rev 17280)
+++ trunk/reactos/subsys/system/sm/win32err.c	2005-08-11 09:07:48 UTC (rev 17281)
@@ -0,0 +1,70 @@
+/* $Id: win32err.c 16861 2005-07-29 13:46:03Z ea $
+ *
+ * win32err.c
+ *
+ * Copyright (c) 1998 Mark Russinovich
+ *	Systems Internals
+ *	http://www.sysinternals.com/
+ *
+ * --------------------------------------------------------------------
+ *
+ * This software is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this software; see the file COPYING.LIB. If
+ * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+ * Cambridge, MA 02139, USA.
+ *
+ * --------------------------------------------------------------------
+ *
+ * Print a Win32 error.
+ *
+ * 1999 February (Emanuele Aliberti)
+ * 	Taken from chkdskx.c and formatx.c by Mark Russinovich
+ * 	to be used in all sysutils.
+ */
+#include <windows.h>
+#include <stdio.h>
+
+//----------------------------------------------------------------------
+//
+// PrintWin32Error
+//
+// Takes the win32 error code and prints the text version.
+//
+//----------------------------------------------------------------------
+void
+PrintWin32Error(
+	PWCHAR	Message,
+	DWORD	ErrorCode
+	)
+{
+	PVOID lpMsgBuf;
+
+	FormatMessageW(
+		(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM),
+		NULL,
+		ErrorCode,
+		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+		(LPWSTR)& lpMsgBuf,
+		0,
+		NULL
+		);
+	wprintf(
+		L"%s: %s\n",
+		Message,
+		lpMsgBuf
+		);
+	LocalFree( lpMsgBuf );
+}
+
+
+/* EOF */