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.

233 lines
4.1 KiB

  1. #include "Precomp.h"
  2. #include "MemberCollection.h"
  3. #include "Confroom.h"
  4. #include "Particip.h"
  5. #include "EnumVar.h"
  6. //////////////////////////////////////////////////////////
  7. // Construction / destruction / initialization
  8. //////////////////////////////////////////////////////////
  9. CMemberCollection::~CMemberCollection()
  10. {
  11. _FreeMemberCollection();
  12. }
  13. //static
  14. HRESULT CMemberCollection::CreateInstance(CSimpleArray<IMember*>& rMemberObjs, IMemberCollection** ppMemberCollection)
  15. {
  16. HRESULT hr = S_OK;
  17. CComObject<CMemberCollection>* p = NULL;
  18. p = new CComObject<CMemberCollection>(NULL);
  19. if(p)
  20. {
  21. p->SetVoid(NULL);
  22. p->InternalFinalConstructAddRef();
  23. hr = p->FinalConstruct();
  24. p->InternalFinalConstructRelease();
  25. if(hr == S_OK)
  26. {
  27. hr = p->QueryInterface(IID_IMemberCollection, reinterpret_cast<void**>(ppMemberCollection));
  28. if(SUCCEEDED(hr))
  29. {
  30. hr = p->_Init(rMemberObjs);
  31. }
  32. }
  33. if(FAILED(hr))
  34. {
  35. delete p;
  36. *ppMemberCollection = NULL;
  37. }
  38. }
  39. else
  40. {
  41. hr = E_OUTOFMEMORY;
  42. }
  43. return hr;
  44. }
  45. //////////////////////////////////////////////////////////
  46. // IMemberCollection
  47. //////////////////////////////////////////////////////////
  48. STDMETHODIMP CMemberCollection::get_Item(VARIANT Index, IMember** ppMember)
  49. {
  50. DBGENTRY(CMemberCollection::get_Item);
  51. HRESULT hr = S_OK;
  52. USES_CONVERSION;
  53. if(ppMember)
  54. {
  55. *ppMember = NULL;
  56. switch(Index.vt)
  57. {
  58. case VT_BSTR:
  59. *ppMember = _GetMemberFromName(OLE2T(Index.bstrVal));
  60. if(*ppMember)
  61. {
  62. (*ppMember)->AddRef();
  63. }
  64. else
  65. {
  66. hr = E_FAIL;
  67. }
  68. break;
  69. case VT_I2:
  70. if(m_Members.GetSize() < Index.iVal)
  71. {
  72. *ppMember = m_Members[Index.iVal];
  73. (*ppMember)->AddRef();
  74. }
  75. else
  76. {
  77. hr = E_INVALIDARG;
  78. }
  79. break;
  80. case VT_I4:
  81. if(m_Members.GetSize() < Index.lVal)
  82. {
  83. *ppMember = m_Members[Index.lVal];
  84. (*ppMember)->AddRef();
  85. }
  86. else
  87. {
  88. hr = E_INVALIDARG;
  89. }
  90. break;
  91. default:
  92. hr = E_INVALIDARG;
  93. }
  94. }
  95. else
  96. {
  97. hr = E_POINTER;
  98. }
  99. DBGEXIT_HR(CMemberCollection::get_Item,hr);
  100. return hr;
  101. }
  102. STDMETHODIMP CMemberCollection::_NewEnum(IUnknown** ppunk)
  103. {
  104. DBGENTRY(CMemberCollection::_NewEnum);
  105. HRESULT hr = S_OK;
  106. SAFEARRAY* psa;
  107. SAFEARRAYBOUND rgsabound[1];
  108. rgsabound[0].lLbound = 0;
  109. rgsabound[0].cElements = m_Members.GetSize();
  110. psa = SafeArrayCreate(VT_DISPATCH, m_Members.GetSize(), rgsabound);
  111. if(psa)
  112. {
  113. for(int i = 0; i < m_Members.GetSize(); ++i)
  114. {
  115. CComPtr<IDispatch> spDispatch;
  116. hr = m_Members[i]->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(&spDispatch));
  117. ASSERT(SUCCEEDED(hr));
  118. CComVariant var(spDispatch);
  119. long ix[1] = {i};
  120. SafeArrayPutElement(psa, ix, &var);
  121. }
  122. CEnumVariant* pEnumVar = NULL;
  123. hr = CEnumVariant::Create(psa, m_Members.GetSize(), &pEnumVar);
  124. if(SUCCEEDED(hr))
  125. {
  126. hr = pEnumVar->QueryInterface(IID_IEnumVARIANT, reinterpret_cast<void**>(ppunk));
  127. }
  128. SafeArrayDestroy(psa);
  129. }
  130. else
  131. {
  132. hr = E_OUTOFMEMORY;
  133. }
  134. DBGEXIT_HR(CMemberCollection::_NewEnum,hr);
  135. return hr;
  136. }
  137. STDMETHODIMP CMemberCollection::get_Count(LONG * pnCount)
  138. {
  139. DBGENTRY(CMemberCollection::get_Count);
  140. HRESULT hr = S_OK;
  141. if(pnCount)
  142. {
  143. *pnCount = m_Members.GetSize();
  144. }
  145. else
  146. {
  147. hr = E_OUTOFMEMORY;
  148. }
  149. DBGEXIT_HR(CMemberCollection::get_Count,hr);
  150. return hr;
  151. }
  152. //////////////////////////////////////////////////////////
  153. // Helpers
  154. //////////////////////////////////////////////////////////
  155. HRESULT CMemberCollection::_Init(CSimpleArray<IMember*>& rMemberObjs)
  156. {
  157. HRESULT hr = S_OK;
  158. for(int i = 0; i < rMemberObjs.GetSize(); ++i)
  159. {
  160. IMember* pMember = rMemberObjs[i];
  161. pMember->AddRef();
  162. m_Members.Add(pMember);
  163. }
  164. return hr;
  165. }
  166. void CMemberCollection::_FreeMemberCollection()
  167. {
  168. for(int i = 0; i < m_Members.GetSize(); ++i)
  169. {
  170. m_Members[i]->Release();
  171. }
  172. m_Members.RemoveAll();
  173. }
  174. IMember* CMemberCollection::_GetMemberFromName(LPCTSTR pszName)
  175. {
  176. IMember* pRet = NULL;
  177. USES_CONVERSION;
  178. for(int i = 0; i < m_Members.GetSize(); ++i)
  179. {
  180. CComBSTR bstrName;
  181. if(SUCCEEDED(m_Members[i]->get_Name(&bstrName)))
  182. {
  183. if(!lstrcmp(OLE2T(bstrName),pszName))
  184. {
  185. pRet = m_Members[i];
  186. break;
  187. }
  188. }
  189. }
  190. return pRet;
  191. }