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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
//*************************************************************
//
// Debugging functions
//
// Microsoft Confidential
// Copyright (c) Microsoft Corporation 1995
// All rights reserved
//
//*************************************************************
#include "uenv.h"
#if DBG
//
// Global Variable containing the debugging level.
//
DWORD dwDebugLevel;
//
// Debug strings
//
const TCHAR c_szUserEnv[] = TEXT("USERENV: ");
const TCHAR c_szCRLF[] = TEXT("\r\n");
//
// Registry debug information
//
#define DEBUG_REG_LOCATION TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\winlogon")
#define DEBUG_KEY_NAME TEXT("UserEnvDebugLevel")
//*************************************************************
//
// InitDebugSupport()
//
// Purpose: Sets the debugging level.
// Also checks the registry for a debugging level.
//
// Parameters: None
//
// Return: void
//
// Comments:
//
//
// History: Date Author Comment
// 5/25/95 ericflo Created
//
//*************************************************************
void InitDebugSupport(void)
{
LONG lResult;
HKEY hKey;
DWORD dwType, dwSize;
//
// Initialize the debug level to normal
//
dwDebugLevel = DL_NORMAL;
//
// Check the registry
//
lResult = RegOpenKey (HKEY_LOCAL_MACHINE, DEBUG_REG_LOCATION,
&hKey);
if (lResult == ERROR_SUCCESS) {
dwSize = sizeof(dwDebugLevel);
RegQueryValueEx(hKey, DEBUG_KEY_NAME, NULL, &dwType,
(LPBYTE)&dwDebugLevel, &dwSize);
RegCloseKey(hKey);
}
}
//*************************************************************
//
// DebugMsg()
//
// Purpose: Displays debug messages based on the debug level
// and type of debug message.
//
// Parameters: mask - debug message type
// pszMsg - debug message
// ... - variable number of parameters
//
// Return: void
//
//
// Comments:
//
//
// History: Date Author Comment
// 5/25/95 ericflo Created
//
//*************************************************************
void _DebugMsg(UINT mask, LPCTSTR pszMsg, ...)
{
BOOL bOutput;
TCHAR szDebugBuffer[2*MAX_PATH+40];
va_list marker;
DWORD dwErrCode;
//
// Save the last error code (so the debug output doesn't change it).
//
dwErrCode = GetLastError();
//
// Detemerine the correct amount of debug output
//
switch (LOWORD(dwDebugLevel)) {
case DL_VERBOSE:
bOutput = TRUE;
break;
case DL_NORMAL:
//
// Normal debug output. Don't
// display verbose stuff, but
// do display warnings/asserts.
//
if (mask != DM_VERBOSE) {
bOutput = TRUE;
} else {
bOutput = FALSE;
}
break;
case DL_NONE:
default:
//
// Only display asserts
//
if (mask == DM_ASSERT) {
bOutput = TRUE;
} else {
bOutput = FALSE;
}
break;
}
//
// Display the error message if appropriate
//
if (bOutput) {
va_start(marker, pszMsg);
wvsprintf(szDebugBuffer, pszMsg, marker);
OutputDebugString(c_szUserEnv);
OutputDebugString(szDebugBuffer);
OutputDebugString(c_szCRLF);
va_end(marker);
if (dwDebugLevel & DL_LOGFILE) {
HANDLE hFile;
DWORD dwBytesWritten;
hFile = CreateFile(TEXT("c:\\userenv.log"),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile != INVALID_HANDLE_VALUE) {
if (SetFilePointer (hFile, 0, NULL, FILE_END) != 0xFFFFFFFF) {
WriteFile (hFile, (LPCVOID) szDebugBuffer,
lstrlen (szDebugBuffer) * sizeof(TCHAR),
&dwBytesWritten,
NULL);
WriteFile (hFile, (LPCVOID) c_szCRLF,
lstrlen (c_szCRLF) * sizeof(TCHAR),
&dwBytesWritten,
NULL);
}
CloseHandle (hFile);
}
}
}
//
// Restore the last error code
//
SetLastError(dwErrCode);
//
// Break to the debugger if appropriate
//
if (mask == DM_ASSERT) {
DebugBreak();
}
}
#endif // DBG
|