1 /* 2 * win32err.c 3 * 4 * Copyright (c) 1998 Mark Russinovich 5 * Systems Internals 6 * http://www.sysinternals.com/ 7 * 8 * -------------------------------------------------------------------- 9 * 10 * This software is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Library General Public License as 12 * published by the Free Software Foundation; either version 2 of the 13 * License, or (at your option) any later version. 14 * 15 * This software is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Library General Public License for more details. 19 * 20 * You should have received a copy of the GNU Library General Public 21 * License along with this software; see the file COPYING.LIB. If 22 * not, write to the Free Software Foundation, Inc., 675 Mass Ave, 23 * Cambridge, MA 02139, USA. 24 * 25 * -------------------------------------------------------------------- 26 * 27 * Print a Win32 error. 28 * 29 * 1999 February (Emanuele Aliberti) 30 * Taken from chkdskx.c and formatx.c by Mark Russinovich 31 * to be used in all sysutils. 32 */ 33 #include <windows.h> 34 #include <stdio.h> 35 36 //---------------------------------------------------------------------- 37 // 38 // PrintWin32Error 39 // 40 // Takes the win32 error code and prints the text version. 41 // 42 //---------------------------------------------------------------------- 43 void 44 PrintWin32Error( 45 PWCHAR Message, 46 DWORD ErrorCode 47 ) 48 { 49 PVOID lpMsgBuf; 50 51 FormatMessageW( 52 (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM), 53 NULL, 54 ErrorCode, 55 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 56 (LPWSTR)& lpMsgBuf, 57 0, 58 NULL 59 ); 60 wprintf( 61 L"%s: %s\n", 62 Message, 63 lpMsgBuf 64 ); 65 LocalFree( lpMsgBuf ); 66 } 67 68 69 /* EOF */ 70