home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / sharewar / apaths / APSOURCE.ZIP / SysError.c < prev    next >
C/C++ Source or Header  |  2001-03-26  |  979b  |  39 lines

  1. /* SysError - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This module retrieves the most recent system error message string.
  6. **
  7. **      Called:     err    = current system error code.
  8. **                  string = string buffer to be filled.
  9. **
  10. **      Returns:    System error message.
  11. */
  12.  
  13. #include "AppPaths.h"
  14.  
  15. extern LPSTR far SysError (DWORD err,LPSTR string)
  16. {
  17.     auto int        len;
  18.     auto char       msg[PSTRING];
  19.  
  20.     *msg = EOS;
  21.  
  22.     FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM,
  23.                    NULL,
  24.                    err,
  25.                    MAKELANGID (LANG_NEUTRAL,SUBLANG_DEFAULT),
  26.                    msg,
  27.                    PSTRING - 1,
  28.                    NULL);
  29.  
  30.     if ((len = lstrlen (msg)) > 2)    // trim the CR/LF termination
  31.         msg[len - 2] = EOS;
  32.  
  33.     lstrcpy (string,msg);
  34.  
  35.     return (string);
  36. }
  37.  
  38. /* end of SysError.c - written by Gregory Braun */
  39.