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.

161 lines
4.6 KiB

  1. /********************************************************************
  2. Copyright (c) 1995-2000 Microsoft Corporation
  3. Module Name:
  4. ntevents.cpp
  5. Abstract:
  6. Defines a generic class that can register an NT
  7. event source and log NT events on that evens source.
  8. Revision History:
  9. rsraghav created 03/10/95
  10. DerekM modified 04/06/99
  11. ********************************************************************/
  12. #include "stdafx.h"
  13. #include "ntevents.h"
  14. /////////////////////////////////////////////////////////////////////////////
  15. // tracing
  16. #ifdef THIS_FILE
  17. #undef THIS_FILE
  18. #endif
  19. static char __szTraceSourceFile[] = __FILE__;
  20. #define THIS_FILE __szTraceSourceFile
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CWebLog- initialization stuff
  23. // **************************************************************************
  24. CNTEvent::CNTEvent(void)
  25. {
  26. m_hEventSource = INVALID_HANDLE_VALUE;
  27. }
  28. // **************************************************************************
  29. CNTEvent::~CNTEvent()
  30. {
  31. if (m_hEventSource != INVALID_HANDLE_VALUE)
  32. {
  33. DeregisterEventSource(m_hEventSource);
  34. m_hEventSource = NULL;
  35. }
  36. }
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CWebLog- exposed methods
  39. // **************************************************************************
  40. HRESULT CNTEvent::InitEventLog(LPCWSTR wszEventSourceName)
  41. {
  42. USE_TRACING("CNTEvent::InitEventLog");
  43. if (wszEventSourceName == NULL)
  44. return E_INVALIDARG;
  45. m_hEventSource = RegisterEventSourceW(NULL, wszEventSourceName);
  46. if (m_hEventSource == INVALID_HANDLE_VALUE)
  47. return Err2HR(GetLastError());
  48. return NOERROR;
  49. }
  50. // **************************************************************************
  51. HRESULT CNTEvent::TerminateEventLog(void)
  52. {
  53. USE_TRACING("CNTEvent::TerminateEventLog");
  54. HRESULT hr = NOERROR;
  55. if (m_hEventSource != INVALID_HANDLE_VALUE)
  56. {
  57. TESTBOOL(hr, DeregisterEventSource(m_hEventSource))
  58. }
  59. m_hEventSource = INVALID_HANDLE_VALUE;
  60. return hr;
  61. }
  62. // **************************************************************************
  63. HRESULT CNTEvent::LogEvent(WORD wEventType, DWORD dwEventID, LPCWSTR wszParam1,
  64. LPCWSTR wszParam2, LPCWSTR wszParam3, LPCWSTR wszParam4,
  65. LPCWSTR wszParam5, LPCWSTR wszParam6, LPCWSTR wszParam7,
  66. LPCWSTR wszParam8, LPCWSTR wszParam9)
  67. {
  68. USE_TRACING("CNTEvent::LogEvent");
  69. HRESULT hr = NOERROR;
  70. if (m_hEventSource == INVALID_HANDLE_VALUE)
  71. return E_FAIL;
  72. LPCWSTR wszInsertString[10];
  73. WORD cInsertStrings = 0;
  74. if (wszParam1 != NULL)
  75. {
  76. cInsertStrings++;
  77. wszInsertString[0] = wszParam1;
  78. if (wszParam2 != NULL)
  79. {
  80. cInsertStrings++;
  81. wszInsertString[1] = wszParam2;
  82. if (wszParam3 != NULL)
  83. {
  84. cInsertStrings++;
  85. wszInsertString[2] = wszParam3;
  86. if (wszParam4 != NULL)
  87. {
  88. cInsertStrings++;
  89. wszInsertString[3] = wszParam4;
  90. if (wszParam5 != NULL)
  91. {
  92. cInsertStrings++;
  93. wszInsertString[4] = wszParam5;
  94. if (wszParam6 != NULL)
  95. {
  96. cInsertStrings++;
  97. wszInsertString[5] = wszParam6;
  98. if (wszParam7 != NULL)
  99. {
  100. cInsertStrings++;
  101. wszInsertString[6] = wszParam7;
  102. if (wszParam8 != NULL)
  103. {
  104. cInsertStrings++;
  105. wszInsertString[7] = wszParam8;
  106. if (wszParam9 != NULL)
  107. {
  108. cInsertStrings++;
  109. wszInsertString[8] = wszParam9;
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. TESTBOOL(hr, ReportEventW(m_hEventSource, wEventType, 0, dwEventID, NULL,
  120. cInsertStrings, 0, (LPCWSTR *)wszInsertString,
  121. NULL))
  122. return hr;
  123. }