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.

168 lines
3.7 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // Components.cpp : Implementation of CComponents
  3. // Copyright (c) Microsoft Corporation 1999.
  4. #include "stdafx.h"
  5. #include <Tuner.h>
  6. #include "Components.h"
  7. #include "MPEG2Component.h"
  8. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_Component, CComponent)
  9. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_MPEG2Component, CMPEG2Component)
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CComponents
  12. STDMETHODIMP CComponents::get_Count(long *pVal)
  13. {
  14. try {
  15. if (!pVal) {
  16. return E_POINTER;
  17. }
  18. ATL_LOCK();
  19. *pVal = m_Components.size();
  20. } catch (...) {
  21. return E_POINTER;
  22. }
  23. return NOERROR;
  24. }
  25. STDMETHODIMP CComponents::get__NewEnum(IEnumVARIANT **ppVal)
  26. {
  27. try {
  28. if (ppVal == NULL)
  29. return E_POINTER;
  30. ComponentEnumerator_t* p;
  31. *ppVal = NULL;
  32. HRESULT hr = ComponentEnumerator_t::CreateInstance(&p);
  33. if (FAILED(hr) || !p) {
  34. return E_OUTOFMEMORY;
  35. }
  36. ATL_LOCK();
  37. hr = p->Init(GetUnknown(), m_Components);
  38. if (FAILED(hr)) {
  39. delete p;
  40. return hr;
  41. }
  42. hr = p->QueryInterface(__uuidof(IEnumVARIANT), (void**)ppVal);
  43. if (FAILED(hr)) {
  44. delete p;
  45. return hr;
  46. }
  47. return NOERROR;
  48. } catch(...) {
  49. return E_POINTER;
  50. }
  51. }
  52. STDMETHODIMP CComponents::EnumComponents(IEnumComponents** pVal)
  53. {
  54. ComponentBaseEnumerator_t *pe = NULL;
  55. ComponentBaseEnumerator_t::CreateInstance(&pe);
  56. pe->Init(static_cast<IComponents*>(this), m_Components);
  57. HRESULT hr = pe->QueryInterface(pVal);
  58. if (FAILED(hr)) {
  59. delete pe;
  60. }
  61. return hr;
  62. }
  63. STDMETHODIMP CComponents::get_Item(VARIANT varIndex, IComponent **ppComponent)
  64. {
  65. try {
  66. if (!ppComponent) {
  67. return E_POINTER;
  68. }
  69. int idx;
  70. CComVariant vidx;
  71. if (FAILED(vidx.ChangeType(VT_I4, &varIndex))) {
  72. return E_INVALIDARG;
  73. }
  74. idx = vidx.lVal;
  75. if (idx >= m_Components.size()) {
  76. return E_INVALIDARG;
  77. }
  78. *ppComponent = *(m_Components.begin() + idx);
  79. (*ppComponent)->AddRef();
  80. } catch (...) {
  81. return E_POINTER;
  82. }
  83. return NOERROR;
  84. }
  85. STDMETHODIMP CComponents::Add(IComponent *pComponent, VARIANT *pNewIndex)
  86. {
  87. try {
  88. if (!pComponent) {
  89. return E_POINTER;
  90. }
  91. PQComponent p(pComponent);
  92. m_Components.push_back(p);
  93. if (pNewIndex) {
  94. VariantClear(pNewIndex);
  95. pNewIndex->vt = VT_UI4;
  96. pNewIndex->ulVal = m_Components.end() - m_Components.begin() - 1;
  97. }
  98. } catch (...) {
  99. return E_POINTER;
  100. }
  101. return NOERROR;
  102. }
  103. STDMETHODIMP CComponents::Remove(VARIANT varIndex)
  104. {
  105. try {
  106. int idx;
  107. CComVariant vidx;
  108. if (FAILED(vidx.ChangeType(VT_I4, &varIndex))) {
  109. return E_INVALIDARG;
  110. }
  111. idx = vidx.lVal;
  112. if (idx >= m_Components.size()) {
  113. return E_INVALIDARG;
  114. }
  115. m_Components.erase(m_Components.begin() + idx);
  116. } catch (...) {
  117. return E_UNEXPECTED;
  118. }
  119. return NOERROR;
  120. }
  121. STDMETHODIMP CComponents::Clone(IComponents **ppNewList)
  122. {
  123. try {
  124. if (!ppNewList) {
  125. return E_POINTER;
  126. }
  127. CComponents* pCs = new CComObject<CComponents>;
  128. if (!pCs) {
  129. return E_OUTOFMEMORY;
  130. }
  131. ComponentList::iterator i;
  132. for (i = m_Components.begin(); i != m_Components.end(); ++i) {
  133. PQComponent p;
  134. HRESULT hr = (*i)->Clone(&p);
  135. if (FAILED(hr)) {
  136. pCs->Release();
  137. return hr;
  138. }
  139. pCs->m_Components.push_back(p);
  140. }
  141. pCs->AddRef();
  142. *ppNewList = pCs;
  143. return NOERROR;
  144. } catch (...) {
  145. return E_UNEXPECTED;
  146. }
  147. return NOERROR;
  148. }