Debugging is required for code writing :)
Sometimes you encounter an error when using your code releasebanben. However, when you switch the code to the debug environment, you cannot find any errors during code debugging. Alternatively, you have a large project and a lot of code. It may take a long time to debug any errors.
The following practical code snippet can be added to your code to locate errors conveniently and quickly:
# Ifdef _ debug
# Define trace_entry debugmessage (L "% s (entry)/n", _ T (_ function __));
# Define trace_exit debugmessage (L "% s (exit)/n", _ T (_ function __));
# Define trace_return (HR) {debugmessage (L "% s (exit) [0x % x]/n", _ T (_ function _), HR ); return hr ;}
# Define trace_exception debugmessage (L "% s (exception) [% s, % d]/n", _ T (_ function __), _ T (_ file _), _ line __);
# Define trace (l, m) debugmessage (L "% s (% s) % s/n", _ T (_ function _), L, M );
# Define trace_debug (m) trace (L "debug", M );
# Define trace_info (m) trace (L "info", M );
# Define trace_notice (m) trace (L "notice", M );
# Define trace_warning (m) trace (L "warning", M );
# Define trace_error (m) trace (L "error", M );
# Else
# Define trace_entry _ Noop;
# Define trace_exit _ Noop;
# Define trace_return (HR) return hr;
# Define trace_exception debugmessage (L "% s (exception) [% s, % d]/n", _ T (_ function __), _ T (_ file _), _ line __);
# Define trace (l, m) _ Noop;
# Define trace_debug (m) _ Noop;
# Define trace_info (m) _ Noop;
# Define trace_notice (m) _ Noop;
# Define trace_warning (m) _ Noop;
# Define trace_error (m) _ Noop;
# Endif
Bool debugmessage (lpcwstr lpszmessage ,...)
{
Bool bresult;
Va_list valist;
// Pass the variable parameters to debugmessagev to be processed.
Va_start (valist, lpszmessage );
Bresult = debugmessagev (max_path, lpszmessage, valist );
Va_end (valist );
Return bresult;
}
Static bool debugmessagev (DWORD dwsize, lpcwstr lpszmessage, va_list Arglist)
{
Lpwstr lpszmsgbuf;
Hresult;
// Parameter checking.
If (null = lpszmessage)
|
(0 = dwsize)
)
{
Return false;
}
// Allocate memory for message buffer.
Lpszmsgbuf = new wchar [dwsize + 1];
If (null = lpszmsgbuf)
Return false;
// Pass the variable parameters to wvsprintf to be formated.
Hresult = stringcbvprintfw (lpszmsgbuf, (dwsize + 1) * sizeof (wchar), lpszmessage, Arglist );
// Dump string to debug output.
Outputdebugstringw (lpszmsgbuf );
// Clean up.
Delete [] lpszmsgbuf;
Return succeeded (hresult );
}
Then, you can use them as follows:
Void
Dwfprinterddi: setcolorfrombrush (dwfprintdocument: tw2dpage * pw2dpage,
Brushobj * pbrush,
Dwfprintjob: tecoloroption ecoloroption)
{
Trace_entry;
//
// Write your own code here
//
Trace_error (L "Internal printdocument missing! ");
Trace_error (L "Internal page missing! ");
Trace_error (L "internal class factory object missing! ");
Trace_warning (L "cannot handle ROP-recording region to copy from mirror ");
Trace_return (RC );
Trace_debug (L "testing for overlapped bitmaps ...");
Trace_notice (L "stroke path contains bezercurve path ");
Trace_notice (L "stroke path contains ellipse ");
Trace_debug (L "clip is trivial, enumerate ");
Trace_exit;
}