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.

235 lines
5.0 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: csenum.cxx
  7. //
  8. // Contents: Per Class Container Package Enumeration
  9. //
  10. //
  11. // History: 09-09-96 DebiM created
  12. // 11-01-97 DebiM modified, moved to cstore
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "dsbase.hxx"
  16. #include "csenum.hxx"
  17. //IEnumPackage implementation.
  18. HRESULT CEnumPackage::QueryInterface(REFIID riid, void** ppObject)
  19. {
  20. if (riid==IID_IUnknown || riid==IID_IEnumPackage)
  21. {
  22. *ppObject=(IEnumPackage *) this;
  23. }
  24. else
  25. {
  26. return E_NOINTERFACE;
  27. }
  28. AddRef();
  29. return S_OK;
  30. }
  31. ULONG CEnumPackage::AddRef()
  32. {
  33. InterlockedIncrement((long*) &m_dwRefCount);
  34. return m_dwRefCount;
  35. }
  36. ULONG CEnumPackage::Release()
  37. {
  38. ULONG dwRefCount=m_dwRefCount-1;
  39. if (InterlockedDecrement((long*) &m_dwRefCount)==0)
  40. {
  41. delete this;
  42. return 0;
  43. }
  44. return dwRefCount;
  45. }
  46. // IEnumPackage methods
  47. //extern DBBINDING InstallBinding [];
  48. //
  49. // CEnumPackage::Next
  50. // ------------------
  51. //
  52. //
  53. //
  54. // Synopsis: This method returns the next celt number of packages
  55. // within the scope of the enumeration.
  56. // Packages are returned in the alphabetical name order.
  57. //
  58. // Arguments: [in] celt - Number of package details to fetch
  59. // INSTALLINFO *rgelt - Package detail structure
  60. // ULONG *pceltFetched - Number of packages returned
  61. //
  62. // Returns: S_OK or S_FALSE if short of packages
  63. //
  64. //
  65. //
  66. HRESULT CEnumPackage::Next(ULONG celt,
  67. PACKAGEDISPINFO *rgelt,
  68. ULONG *pceltFetched)
  69. {
  70. ULONG cgot = 0;
  71. HRESULT hr = S_OK;
  72. Data *pData;
  73. LPOLESTR name;
  74. if ((celt > 1) && (!pceltFetched))
  75. return E_INVALIDARG;
  76. if (pceltFetched)
  77. (*pceltFetched) = 0;
  78. if (!IsValidPtrOut(rgelt, sizeof(PACKAGEDISPINFO)*celt))
  79. return E_INVALIDARG;
  80. hr = FetchPackageInfo(m_pIRow,
  81. m_HAcc,
  82. m_dwAppFlags,
  83. m_pdwLocale,
  84. m_pPlatform,
  85. celt,
  86. &cgot,
  87. rgelt);
  88. //
  89. // BUGBUG. Check for errors.
  90. //
  91. if (cgot != celt)
  92. hr = S_FALSE;
  93. else
  94. hr = S_OK;
  95. m_dwPosition += cgot;
  96. if (pceltFetched)
  97. *pceltFetched = cgot;
  98. return hr;
  99. }
  100. HRESULT CEnumPackage::Skip(ULONG celt)
  101. {
  102. ULONG celtFetched = NULL, i;
  103. HRESULT hr = S_OK;
  104. PACKAGEDISPINFO *pIf = NULL;
  105. pIf = new PACKAGEDISPINFO[celt];
  106. hr = Next(celt, pIf, &celtFetched);
  107. for (i = 0; i < celtFetched; i++)
  108. ReleasePackageInfo(pIf+i);
  109. delete pIf;
  110. return hr;
  111. }
  112. HRESULT CEnumPackage::Reset()
  113. {
  114. m_dwPosition = 0;
  115. return m_pIRow->RestartPosition(NULL);
  116. }
  117. // BUGBUG:: Positioning
  118. HRESULT CEnumPackage::Clone(IEnumPackage **ppenum)
  119. {
  120. CEnumPackage *pClone = new CEnumPackage;
  121. HRESULT hr = S_OK, hr1 = S_OK;
  122. hr = pClone->Initialize(m_CommandText, m_dwAppFlags, m_pdwLocale, m_pPlatform);
  123. if (FAILED(hr)) {
  124. delete pClone;
  125. return hr;
  126. }
  127. hr = pClone->QueryInterface(IID_IEnumPackage, (void **)ppenum);
  128. if (m_dwPosition)
  129. hr1 = pClone->Skip(m_dwPosition);
  130. // we do not want to return the error code frm skip.
  131. return hr;
  132. }
  133. CEnumPackage::CEnumPackage()
  134. {
  135. m_dwRefCount = 0;
  136. m_HAcc = NULL;
  137. m_pIRow = NULL;
  138. m_pIAccessor = NULL;
  139. m_CommandText = NULL;
  140. m_dwPosition = 0;
  141. m_pIDBCreateCommand = NULL;
  142. m_pdwLocale = NULL;
  143. m_pPlatform = NULL;
  144. StartQuery(&(m_pIDBCreateCommand));
  145. }
  146. HRESULT CEnumPackage::Initialize(LPOLESTR szCommandText,
  147. DWORD dwAppFlags,
  148. DWORD *pdwLocale,
  149. CSPLATFORM *pPlatform)
  150. {
  151. HRESULT hr;
  152. m_CommandText = (LPOLESTR)CoTaskMemAlloc (sizeof(WCHAR) * (wcslen(szCommandText)+1));
  153. if (!m_CommandText)
  154. return E_OUTOFMEMORY;
  155. wcscpy(m_CommandText, szCommandText);
  156. m_dwAppFlags = dwAppFlags;
  157. if (pdwLocale)
  158. {
  159. m_pdwLocale = (DWORD *) CoTaskMemAlloc(sizeof(DWORD));
  160. *m_pdwLocale = *pdwLocale;
  161. }
  162. if (pPlatform)
  163. {
  164. m_pPlatform = (CSPLATFORM *) CoTaskMemAlloc(sizeof(CSPLATFORM));
  165. memcpy (m_pPlatform, pPlatform, sizeof(CSPLATFORM));
  166. }
  167. hr = ExecuteQuery (m_pIDBCreateCommand,
  168. szCommandText,
  169. PACKAGEENUM_COLUMN_COUNT,
  170. NULL,
  171. &m_HAcc,
  172. &m_pIAccessor,
  173. &m_pIRow
  174. );
  175. if (FAILED(hr))
  176. {
  177. return hr;
  178. }
  179. return S_OK;
  180. }
  181. CEnumPackage::~CEnumPackage()
  182. {
  183. if (m_CommandText)
  184. CoTaskMemFree (m_CommandText);
  185. if (m_pdwLocale)
  186. CoTaskMemFree (m_pdwLocale);
  187. CloseQuery(m_pIAccessor,
  188. m_HAcc,
  189. m_pIRow);
  190. EndQuery(m_pIDBCreateCommand);
  191. }
  192.