Debug mode application output debug debug information (ready-made macro definition for formatting printing information)

Source: Internet
Author: User

[CPP]View PlainCopy
  1. Debug mode, the main output of some debugging information.
  2. #ifdef UNICODE
  3. #define _FILE_ _str2wstr (__file__)
  4. #define _function_ _str2wstr (__function__)
  5. #else
  6. #define _FILE_ __file__
  7. #define _function_ __function__
  8. #endif
  9. #define MAX_BUF_SIZE (1024)
  10. #define MAX_BIN_COUNT (16)
  11. #define MAX_BIN_SIZE (64)
  12. #ifdef _DEBUG
  13. #define NEW Debug_new
  14. #define DBGPRINT (lpszfmt, ...) \
  15. TCHAR sztext[1024] = {0}; \
  16. stringcchprintf (Sztext, _countof (Sztext), lpszfmt, __va_args__); \
  17. OutputDebugString (Sztext);
  18. #define DBGFAILED (dwerror) \
  19. LPTSTR lpszbuf = NULL; \  
  20. TCHAR szerror[1024] = {0}; \  
  21. FormatMessage (Format_message_allocate_buffer | Format_message_from_system, NULL, Dwerror, Lang_neutral, (LPTSTR) &lpszbuf, 0, NULL); \  
  22. stringcchprintf (Szerror, _countof (szerror), _t ("\nerror:file:%s \n\tline:%d Function:%s () \n\treason:%s\n"), _    File_, __line__, _function_, lpszbuf); \  
  23. OutputDebugString (szerror); \
  24. LocalFree (LPSZBUF);
  25. #define DUMPBIN (pData, dwsize) \
  26. TCHAR Szdata[max_bin_size] = {0}; \
  27. Traceloginfo (_t ("\ n-----------00-01-02-03-04-05-06-07-08-09-0a-0b-0c-0d-0e-0f"));
  28. For (DWORD i = 0; i < dwsize; i++) \
  29. { \
  30. if (0 = = (i% max_bin_count)) \
  31. { \
  32. Traceloginfo (Szdata); \
  33. stringcchprintf (Szdata, _countof_ (szdata), _t ("\n%08xh:%02x"), I, pdata[i]); \
  34. } \
  35. else \
  36. { \
  37. stringcchprintf (Szdata + _tcslen (szdata), _countof_ (szdata)-_tcslen (Szdata), _t ("%02x"), pdata[i]); \
  38. } \
  39. } \
  40. OutputDebugString (Szdata); \
  41. OutputDebugString (_t ("\ n----------------------------------------------------------\ n"));
  42. #else
  43. #define DBGPRINT (lpszfmt, ...)
  44. #define DBGFAILED ()
  45. #define DUMPBIN (PData, dwsize)
  46. #endif


http://blog.csdn.net/visualeleven/article/details/7211249

Debug mode application output debug debug information (ready-made macro definition for formatting printing information)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.