Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
212 | dhylands | 1 | /**************************************************************************** |
2 | * |
||
3 | * Copyright (c) 2003 Dave Hylands |
||
4 | * All Rights Reserved |
||
5 | * |
||
6 | * Permission is granted to any individual or institution to use, copy, or |
||
7 | * redistribute this software so long as it is not sold for profit, and that |
||
8 | * this copyright notice is retained. |
||
9 | * |
||
10 | ****************************************************************************/ |
||
11 | /** |
||
12 | * |
||
13 | * @file Error.cpp |
||
14 | * |
||
15 | * @brief Implements the error helper functions. |
||
16 | * |
||
17 | ****************************************************************************/ |
||
18 | |||
19 | // ---- Include Files ------------------------------------------------------- |
||
20 | |||
21 | #include "Error.h" |
||
22 | #include "Str.h" |
||
23 | |||
24 | #define WIN32_LEAN_AND_MEAN |
||
25 | #include <windows.h> |
||
26 | |||
27 | // ---- Public Variables ---------------------------------------------------- |
||
28 | // ---- Private Constants and Types ----------------------------------------- |
||
29 | // ---- Private Variables --------------------------------------------------- |
||
30 | // ---- Private Function Prototypes ----------------------------------------- |
||
31 | // ---- Functions ----------------------------------------------------------- |
||
32 | |||
33 | /** |
||
34 | * @addtogroup Error |
||
35 | * @{ |
||
36 | */ |
||
37 | |||
38 | |||
39 | //*************************************************************************** |
||
40 | /** |
||
41 | * Translates error number @a errNum into a string. |
||
42 | * |
||
43 | * @returns A pointer to errStr. |
||
44 | */ |
||
45 | |||
46 | char *GetErrorStr |
||
47 | ( |
||
48 | DWORD errNum, ///< Error number to get the string version for. |
||
49 | char *errStr, ///< Place to store the error string. |
||
50 | size_t maxLen ///< Max length that can be written into errStr. |
||
51 | ) |
||
52 | { |
||
53 | if ( FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, // dwFlags |
||
54 | 0, // lpSource |
||
55 | errNum, // dwMessageId |
||
56 | GetUserDefaultLangID(), // dwlanguageId |
||
57 | errStr, // lpBuffer |
||
58 | maxLen, // nSize |
||
59 | NULL ) == 0 ) // arguments |
||
60 | { |
||
61 | StrPrintf( errStr, maxLen, "*** Unknown Error: %d ***", errNum ); |
||
62 | } |
||
63 | |||
64 | return errStr; |
||
65 | |||
66 | } // GetErrorStr |
||
67 | |||
68 | //*************************************************************************** |
||
69 | /** |
||
70 | * Translates the result of calling @a GetLastError() into a string. |
||
71 | * |
||
72 | * @returns A pointer to errStr. |
||
73 | */ |
||
74 | |||
75 | char *GetLastErrorStr |
||
76 | ( |
||
77 | char *errStr, ///< Place to store the error string. |
||
78 | size_t maxLen ///< Max length that can be written into errStr. |
||
79 | ) |
||
80 | { |
||
81 | return GetErrorStr( GetLastError(), errStr, maxLen ); |
||
82 | |||
83 | } // GetLastErrorStr |
||
84 | |||
85 | /** @} */ |
||
86 | |||
87 |