summaryrefslogtreecommitdiff
path: root/print/XPSDrvSmpl/src/debug/debug.cpp
diff options
context:
space:
mode:
authorJ M Rossy <[email protected]>2015-08-25 11:20:13 -0700
committerJ M Rossy <[email protected]>2015-08-25 11:20:13 -0700
commitf18a140b31cfd0cbd46ceea3e060e78581ee04dd (patch)
treee639de2a642247978a8cbcdd0f37c404d4e0eb00 /print/XPSDrvSmpl/src/debug/debug.cpp
parentd619854c439eb633955f8b1febccd0406908e0a0 (diff)
Fix #12 by modifying gitignore to include some debug folders
Diffstat (limited to 'print/XPSDrvSmpl/src/debug/debug.cpp')
-rw-r--r--print/XPSDrvSmpl/src/debug/debug.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/print/XPSDrvSmpl/src/debug/debug.cpp b/print/XPSDrvSmpl/src/debug/debug.cpp
new file mode 100644
index 00000000..330a4a1d
--- /dev/null
+++ b/print/XPSDrvSmpl/src/debug/debug.cpp
@@ -0,0 +1,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&)
+ {
+ }
+}
+