Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #include "stdafx.h"
  11. #include "Common.h"
  12. #include "AtlTraceModuleManager.h"
  13. extern HINSTANCE g_hInst;
  14. CAtlTraceModuleInfo::CAtlTraceModuleInfo() :
  15. m_hInst(NULL),
  16. m_nCategories(0),
  17. m_iFirstCategory(-1)
  18. {
  19. m_szPath[0] = L'\0';
  20. m_szName[0] = L'\0';
  21. }
  22. void CAtlTraceModuleInfo::Reset(HINSTANCE hInst)
  23. {
  24. WCHAR szModulePath[MAX_PATH] = {L'\0'};
  25. if(0 != (GetVersion() & 0x80000000))
  26. {
  27. USES_CONVERSION;
  28. CHAR szTemp[MAX_PATH];
  29. if(GetModuleFileNameA(hInst, szTemp, MAX_PATH))
  30. wcscpy(szModulePath, A2W(szTemp));
  31. }
  32. else
  33. GetModuleFileNameW(hInst, szModulePath, MAX_PATH);
  34. wcsncpy(m_szPath, szModulePath, MAX_PATH);
  35. WCHAR *pszShortName = m_szPath + wcslen(m_szPath);
  36. while(pszShortName > m_szPath && *(pszShortName - 1) != L'\\')
  37. pszShortName--;
  38. wcsncpy(m_szName, pszShortName, ATL_TRACE_MAX_NAME_SIZE);
  39. m_hInst = hInst;
  40. m_nCategories = 0;
  41. m_iFirstCategory = -1;
  42. }
  43. // Categories
  44. CAtlTraceCategory::CAtlTraceCategory() :
  45. m_nModuleCookie(0)
  46. {
  47. Reset(L"", 0);
  48. }
  49. void CAtlTraceCategory::Reset(const WCHAR *pszName, LONG nModuleCookie)
  50. {
  51. wcsncpy(m_szName, pszName, ATL_TRACE_MAX_NAME_SIZE);
  52. m_nModuleCookie = nModuleCookie;
  53. }
  54. // Modules
  55. CAtlTraceModule::CAtlTraceModule() :
  56. m_pfnCrtDbgReport(NULL)
  57. {
  58. }
  59. void CAtlTraceModule::CrtDbgReport(CAtlTraceModule::fnCrtDbgReport_t pfnCrtDbgReport)
  60. {
  61. #ifdef _DEBUG
  62. m_pfnCrtDbgReport = pfnCrtDbgReport ? pfnCrtDbgReport : _CrtDbgReport;
  63. #else
  64. m_pfnCrtDbgReport = pfnCrtDbgReport ? pfnCrtDbgReport : NULL;
  65. #endif
  66. }
  67. // Processes
  68. CAtlTraceProcess::CAtlTraceProcess(DWORD_PTR dwMaxSize) :
  69. CAtlTraceModuleInfo(),
  70. m_dwId(GetCurrentProcessId()), m_nRef(1), m_dwMaxSize(dwMaxSize),
  71. m_dwFrontAlloc(0), m_dwBackAlloc(0), m_dwCurrFront(0), m_dwCurrBack(0),
  72. m_nLevel(0), m_bLoaded(false), m_bEnabled(true), m_bFuncAndCategoryNames(false), m_bFileNameAndLineNo(false),
  73. m_nNextCookie( 0 )
  74. {
  75. m_pvBase = this;
  76. }
  77. LONG CAtlTraceProcess::GetNextCookie()
  78. {
  79. return( ::InterlockedIncrement( &m_nNextCookie ) );
  80. }