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
|
/*++
Copyright (c) 2005 Microsoft Corporation
All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
File Name:
debug.cpp
Abstract:
Debug implementations.
--*/
#include "precomp.h"
#include "debug.h"
#include "xdstring.h"
/*++
Routine Name:
RealDebugMessage
Routine Description:
This routine takes a debug message and va_list and outputs the message via OutputDebugString
Arguments:
dwSize - Maximum size of the debug message in number of characters
pszMessage - The debug message string
arglist - The arg list for the debug message string
Return Value:
BOOL
TRUE - On success
FALSE - On error
--*/
BOOL
RealDebugMessage(
_In_ DWORD dwSize,
_In_ PCSTR pszMessage,
va_list arglist
)
{
HRESULT hr = S_OK;
PSTR pszMsgBuf;
if (NULL == pszMessage ||
0 == dwSize)
{
hr = E_INVALIDARG;
}
if (SUCCEEDED(hr))
{
//
// Allocate memory for message buffer.
//
pszMsgBuf = new(std::nothrow) CHAR[dwSize + 1];
if (NULL != pszMsgBuf)
{
//
// Pass the variable parameters to wvsprintf to be formated.
//
hr = StringCbVPrintfA(pszMsgBuf, (dwSize + 1) * sizeof(CHAR), pszMessage, arglist);
//
// Dump string to debug output.
//
OutputDebugStringA(pszMsgBuf);
//
// Clean up.
//
delete[] pszMsgBuf;
pszMsgBuf = NULL;
}
else
{
hr = E_OUTOFMEMORY;
}
}
return SUCCEEDED(hr);
}
/*++
Routine Name:
DbgPrint
Routine Description:
This routine takes a format string and arguments and outputs as a debug string
Arguments:
pszFormatString - Format string for the debug message
... - argument list
Return Value:
BOOL
TRUE - On success
FALSE - On error
--*/
BOOL
DbgPrint(
_In_ PCSTR pszFormatString,
...
)
{
BOOL bResult;
va_list VAList;
//
// Pass the variable parameters to RealDebugMessage to be processed.
//
va_start(VAList, pszFormatString);
bResult = RealDebugMessage(0x8000, pszFormatString, VAList);
va_end(VAList);
return bResult;
}
/*++
Routine Name:
DbgDOMDoc
Routine Description:
This routine outputs an XML DOM document to the debug output stream
Arguments:
pszMessage - Debug message
pDomDoc - DOM document to be output
Return Value:
None.
--*/
VOID
DbgDOMDoc(
_In_ PCSTR pszMessage,
_In_ IXMLDOMDocument2* pDomDoc
)
{
try
{
CComBSTR xml;
if (pDomDoc != NULL &&
SUCCEEDED(pDomDoc->get_xml(&xml)))
{
CStringXDA ansi(xml);
if (pszMessage != NULL)
{
DbgPrint("%s%s\n", pszMessage, ansi.GetBuffer());
}
else
{
DbgPrint("%s\n", ansi.GetBuffer());
}
}
}
catch (CXDException&)
{
}
}
|