forked from ritchielawrence/mtee
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperr.cpp
135 lines (110 loc) · 2.01 KB
/
perr.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "header.h"
#define MAX_MSG_BUF_SIZE (1024)
DWORD Perror(DWORD dwErrNum)
{
DWORD cMsgLen;
LPVOID pErrBuf;
DWORD dwLastErr;
dwErrNum ? dwLastErr = dwErrNum : dwLastErr = GetLastError();
//
// get the text description for that error number from the system
//
cMsgLen = FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastErr,
MAKELANGID(0, SUBLANG_ENGLISH_US),
(LPTSTR) &pErrBuf,
MAX_MSG_BUF_SIZE,
NULL
);
if(cMsgLen)
{
Verbose((LPCTSTR) pErrBuf);
LocalFree((HLOCAL) pErrBuf);
}
return dwLastErr;
}
VOID Verbose(LPCTSTR szMsg)
{
DWORD cBytes;
WriteFile
(
GetStdHandle(STD_ERROR_HANDLE),
szMsg,
lstrlen(szMsg),
&cBytes,
NULL
);
}
/*
VOID ShowPipeInfo(HANDLE h)
{
TCHAR z[1024];
DWORD lpFlags;
DWORD lpOutBufferSize;
DWORD lpInBufferSize;
DWORD lpMaxInstances;
DWORD lpState;
DWORD lpCurInstances;
//LPTSTR lpUserName;
//DWORD nMaxUserNameSize;
if(!GetNamedPipeInfo(
h,
&lpFlags,
&lpOutBufferSize,
&lpInBufferSize,
&lpMaxInstances))
{
perr(TEXT("GetNamedPipeInfo()"));
}
if(!GetNamedPipeHandleState(
h,
&lpState,
&lpCurInstances,
NULL,
NULL,
NULL,
NULL))
{
perr(TEXT("GetNamedPipeHandleState"));
}
wsprintf(
z,
TEXT("Handle:\t\t0x%08X\n")
TEXT("Flags:\t\t0x%08X\n")
TEXT("OutBufferSize:\t0x%08X\n")
TEXT("InBufferSize:\t0x%08X\n")
TEXT("MaxInstances:\t0x%08X\n")
TEXT("State:\t\t0x%08X\n")
TEXT("CurInstances:\t0x%08X\n\n"),
h,
lpFlags,
lpOutBufferSize,
lpInBufferSize,
lpMaxInstances,
lpState,
lpCurInstances);
DWORD nBytes;
WriteFile(
GetStdHandle(STD_ERROR_HANDLE),
z,
lstrlen(z) * sizeof(TCHAR),
&nBytes,
NULL);
}
VOID ConfigStdIn(HANDLE h)
{
DWORD lpMode;
lpMode = (PIPE_READMODE_BYTE | PIPE_NOWAIT);
if(!SetNamedPipeHandleState(
h,
&lpMode,
NULL,
NULL))
{
perr(TEXT("SetNamedPipeHandleState()"));
}
}
*/