Leaked source code of windows server 2003
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.

222 lines
3.9 KiB

  1. /*++
  2. Copyright (C) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. logsrc.cpp
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #include "polyline.h"
  9. #include <strsafe.h>
  10. #include "unihelpr.h"
  11. #include "logsrc.h"
  12. #include "utils.h"
  13. // Construction/Destruction
  14. CLogFileItem::CLogFileItem (
  15. CSysmonControl *pCtrl )
  16. : m_cRef ( 0 ),
  17. m_pCtrl ( pCtrl ),
  18. m_pImpIDispatch ( NULL ),
  19. m_pNextItem ( NULL ),
  20. m_szPath ( NULL )
  21. /*++
  22. Routine Description:
  23. Constructor for the CLogFileItem class. It initializes the member variables.
  24. Arguments:
  25. None.
  26. Return Value:
  27. None.
  28. --*/
  29. {
  30. return;
  31. }
  32. CLogFileItem::~CLogFileItem (
  33. VOID
  34. )
  35. /*++
  36. Routine Description:
  37. Destructor for the CLogFileItem class. It frees any objects, storage, and
  38. interfaces that were created. If the item is part of a query it is removed
  39. from the query.
  40. Arguments:
  41. None.
  42. Return Value:
  43. None.
  44. --*/
  45. {
  46. if ( NULL != m_szPath )
  47. delete [] m_szPath;
  48. if ( NULL != m_pImpIDispatch )
  49. delete m_pImpIDispatch;
  50. }
  51. HRESULT
  52. CLogFileItem::Initialize (
  53. LPCWSTR pszPath,
  54. CLogFileItem** pListHead
  55. )
  56. {
  57. HRESULT hr = E_POINTER;
  58. WCHAR* pszNewPath = NULL;
  59. ULONG ulPathLen;
  60. if ( NULL != pszPath ) {
  61. if ( L'\0' != *pszPath ) {
  62. ulPathLen = lstrlen(pszPath) + 1;
  63. pszNewPath = new WCHAR [ulPathLen];
  64. if ( NULL != pszNewPath ) {
  65. StringCchCopy(pszNewPath, ulPathLen, pszPath);
  66. m_szPath = pszNewPath;
  67. hr = S_OK;
  68. } else {
  69. hr = E_OUTOFMEMORY;
  70. }
  71. } else {
  72. hr = E_INVALIDARG;
  73. }
  74. }
  75. if ( SUCCEEDED ( hr ) ) {
  76. m_pNextItem = *pListHead;
  77. *pListHead = this;
  78. }
  79. return hr;
  80. }
  81. /*
  82. * CLogFileItem::QueryInterface
  83. * CLogFileItem::AddRef
  84. * CLogFileItem::Release
  85. */
  86. STDMETHODIMP CLogFileItem::QueryInterface(
  87. IN REFIID riid,
  88. OUT LPVOID *ppv
  89. )
  90. {
  91. HRESULT hr = S_OK;
  92. if (ppv == NULL) {
  93. return E_POINTER;
  94. }
  95. try {
  96. *ppv = NULL;
  97. if (riid == IID_ILogFileItem || riid == IID_IUnknown) {
  98. *ppv = this;
  99. } else if (riid == DIID_DILogFileItem) {
  100. if (m_pImpIDispatch == NULL) {
  101. m_pImpIDispatch = new CImpIDispatch(this, this);
  102. if ( NULL != m_pImpIDispatch ) {
  103. m_pImpIDispatch->SetInterface(DIID_DILogFileItem, this);
  104. *ppv = m_pImpIDispatch;
  105. } else {
  106. hr = E_OUTOFMEMORY;
  107. }
  108. } else {
  109. *ppv = m_pImpIDispatch;
  110. }
  111. } else {
  112. hr = E_NOINTERFACE;
  113. }
  114. if ( SUCCEEDED ( hr ) ) {
  115. ((LPUNKNOWN)*ppv)->AddRef();
  116. }
  117. } catch (...) {
  118. hr = E_POINTER;
  119. }
  120. return hr;
  121. }
  122. STDMETHODIMP_(ULONG) CLogFileItem::AddRef(void)
  123. {
  124. return ++m_cRef;
  125. }
  126. STDMETHODIMP_(ULONG) CLogFileItem::Release(void)
  127. {
  128. if ( 0 == --m_cRef ) {
  129. delete this;
  130. return 0;
  131. }
  132. return m_cRef;
  133. }
  134. STDMETHODIMP CLogFileItem::get_Path (
  135. OUT BSTR* pstrPath
  136. )
  137. {
  138. HRESULT hr = S_OK;
  139. if (pstrPath == NULL) {
  140. return E_POINTER;
  141. }
  142. try {
  143. *pstrPath = NULL;
  144. *pstrPath = SysAllocString ( m_szPath );
  145. if ( NULL == *pstrPath ) {
  146. hr = E_OUTOFMEMORY;
  147. }
  148. } catch (...) {
  149. hr = E_POINTER;
  150. }
  151. return hr;
  152. }
  153. CLogFileItem*
  154. CLogFileItem::Next (
  155. void )
  156. {
  157. return m_pNextItem;
  158. }
  159. void
  160. CLogFileItem::SetNext (
  161. CLogFileItem* pNext )
  162. {
  163. m_pNextItem = pNext;
  164. }
  165. LPCWSTR
  166. CLogFileItem::GetPath (
  167. void )
  168. {
  169. return m_szPath;
  170. }