-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathErrorOut.cpp
36 lines (31 loc) · 1.01 KB
/
ErrorOut.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// simple function for outputting an error, given a string and error code.
#include "precomp.h"
void OutputError(HRESULT hr, LPCSTR operation) {
TCHAR error_string[ERROR_MAX];
TCHAR error_code[ERROR_LENGTH];
memset(error_string, 0, ERROR_MAX);
memset(error_code, 0, ERROR_LENGTH);
switch(hr) {
case STRSAFE_E_INSUFFICIENT_BUFFER:
if (FAILED(StringCchCopy(error_code, ERROR_LENGTH, "insufficient buffer")))
return;
break;
case STRSAFE_E_INVALID_PARAMETER:
if (FAILED(StringCchCopy(error_code, ERROR_LENGTH, "invalid parameter")))
return;
break;
case STRSAFE_E_END_OF_FILE:
if (FAILED(StringCchCopy(error_code, ERROR_LENGTH, "encountering end of file")))
return;
break;
}
if (0 != error_code[0]) {
if (FAILED(StringCchPrintf(error_string, ERROR_MAX, "Unable to perform %s due to %s.\n", operation, error_code)))
return;
}
else
if (FAILED(StringCchPrintf(error_string, ERROR_MAX, "Unable to perform %s.\n", operation)))
return;
OutputDebugString(error_string);
return;
}