Emit Win32 error messages on failure.

svn path=/trunk/; revision=17281
This commit is contained in:
Emanuele Aliberti 2005-08-11 09:07:48 +00:00
parent 97ffde7504
commit f83c14b3fc
5 changed files with 86 additions and 12 deletions

View file

@ -32,8 +32,6 @@ IDS_shutdown_msg, "shutdown an optional environment subsystem;"
IDS_Unknown, "Unknown command '%s'.\n" IDS_Unknown, "Unknown command '%s'.\n"
IDS_Status, "Status 0x%08lx\n"
IDS_SM1, "SM SubSystem Directory\n\n\ IDS_SM1, "SM SubSystem Directory\n\n\
SSID PID Flags\n\ SSID PID Flags\n\
---- -------- ------------\n" ---- -------- ------------\n"

View file

@ -14,14 +14,13 @@
#define IDS_shutdown_msg 209 #define IDS_shutdown_msg 209
#define IDS_Unknown 300 #define IDS_Unknown 300
#define IDS_Not_Imp 301 #define IDS_Not_Imp 301
#define IDS_ID 302 #define IDS_ID 302
#define IDS_SM2 303 #define IDS_SM2 303
#define IDS_SM1 304 #define IDS_SM1 304
#define IDS_Status 305 #define IDS_Mangers 305
#define IDS_Mangers 306 #define IDS_USING 306
#define IDS_USING 307 #define IDS_FAILS_MNG 307
#define IDS_FAILS_MNG 308
/* EOF */ /* EOF */

View file

@ -35,12 +35,21 @@
#include <sm/helper.h> #include <sm/helper.h>
VOID PrintWin32Error(PWCHAR,DWORD); /* win32err.c */
#define SM_CMD(n) cmd_##n #define SM_CMD(n) cmd_##n
#define SM_CMD_DECL(n) int SM_CMD(n)(int argc, char * argv[]) #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)) #define SM_CMD_CALL(n,c,v) SM_CMD(n)((c),(v))
HANDLE hSmApiPort = (HANDLE) 0; HANDLE hSmApiPort = (HANDLE) 0;
VOID STDCALL PrintStatusError (NTSTATUS Status)
{
DWORD Win32Error = RtlNtStatusToDosError (Status);
PrintWin32Error (L"sm", Win32Error);
}
typedef struct _SM_CMD_DESCRIPTOR typedef struct _SM_CMD_DESCRIPTOR
{ {
TCHAR Name[RC_STRING_MAX_SIZE]; TCHAR Name[RC_STRING_MAX_SIZE];
@ -117,9 +126,7 @@ SM_CMD_DECL(boot)
#endif #endif
if (STATUS_SUCCESS != Status) if (STATUS_SUCCESS != Status)
{ {
LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE); PrintStatusError (Status);
_tprintf(UsageMessage, Status);
} }
} }
@ -197,8 +204,7 @@ SM_CMD_DECL(info)
& ReturnDataLength); & ReturnDataLength);
if (STATUS_SUCCESS != Status) if (STATUS_SUCCESS != Status)
{ {
LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE); PrintStatusError (Status);
_tprintf(UsageMessage, Status);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
switch (argc) switch (argc)

View file

@ -6,5 +6,6 @@
<library>ntdll</library> <library>ntdll</library>
<library>kernel32</library> <library>kernel32</library>
<file>sm.c</file> <file>sm.c</file>
<file>win32err.c</file>
<file>sm.rc</file> <file>sm.rc</file>
</module> </module>

View file

@ -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 */