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.

120 lines
2.2 KiB

  1. // SetupClassEnum.cpp : Implementation of CSetupClassEnum
  2. #include "stdafx.h"
  3. #include "DevCon2.h"
  4. #include "SetupClass.h"
  5. #include "SetupClasses.h"
  6. #include "SetupClassEnum.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CSetupClassEnum
  9. CSetupClassEnum::~CSetupClassEnum()
  10. {
  11. DWORD c;
  12. if(pSetupClasses) {
  13. for(c=0;c<Count;c++) {
  14. pSetupClasses[c]->Release();
  15. }
  16. delete [] pSetupClasses;
  17. }
  18. }
  19. HRESULT CSetupClassEnum::Next(
  20. ULONG celt,
  21. VARIANT * rgVar,
  22. ULONG * pCeltFetched
  23. )
  24. {
  25. ULONG fetched;
  26. CSetupClass *pCls;
  27. if(pCeltFetched) {
  28. *pCeltFetched = 0;
  29. }
  30. for(fetched = 0; fetched<celt && Position<Count ; fetched++,Position++) {
  31. VariantInit(&rgVar[fetched]);
  32. pCls = pSetupClasses[Position];
  33. pCls->AddRef();
  34. V_VT(&rgVar[fetched]) = VT_DISPATCH;
  35. V_DISPATCH(&rgVar[fetched]) = pCls;
  36. }
  37. if(pCeltFetched) {
  38. *pCeltFetched = fetched;
  39. }
  40. return (fetched<celt) ? S_FALSE : S_OK;
  41. }
  42. HRESULT CSetupClassEnum::Skip(
  43. ULONG celt
  44. )
  45. {
  46. DWORD remaining = Count-Position;
  47. if(remaining<celt) {
  48. Position = Count;
  49. return S_FALSE;
  50. } else {
  51. Position += (DWORD)celt;
  52. return S_OK;
  53. }
  54. }
  55. HRESULT CSetupClassEnum::Reset(
  56. )
  57. {
  58. Position = 0;
  59. return S_OK;
  60. }
  61. HRESULT CSetupClassEnum::Clone(
  62. IEnumVARIANT ** ppEnum
  63. )
  64. {
  65. *ppEnum = NULL;
  66. HRESULT hr;
  67. CComObject<CSetupClassEnum> *pEnum = NULL;
  68. hr = CComObject<CSetupClassEnum>::CreateInstance(&pEnum);
  69. if(FAILED(hr)) {
  70. return hr;
  71. }
  72. if(!pEnum) {
  73. return E_OUTOFMEMORY;
  74. }
  75. if(!pEnum->CopySetupClasses(pSetupClasses,Count)) {
  76. delete pEnum;
  77. return E_OUTOFMEMORY;
  78. }
  79. pEnum->Position = Position;
  80. pEnum->AddRef();
  81. *ppEnum = pEnum;
  82. return S_OK;
  83. }
  84. BOOL CSetupClassEnum::CopySetupClasses(CSetupClass **pArray, DWORD NewCount)
  85. {
  86. DWORD c;
  87. if(pSetupClasses) {
  88. delete [] pSetupClasses;
  89. pSetupClasses = NULL;
  90. }
  91. Count = 0;
  92. Position = 0;
  93. pSetupClasses = new CSetupClass*[NewCount];
  94. if(!pSetupClasses) {
  95. return FALSE;
  96. }
  97. for(c=0;c<NewCount;c++) {
  98. pArray[c]->AddRef();
  99. pSetupClasses[c] = pArray[c];
  100. if(!pSetupClasses[c]) {
  101. Count = c;
  102. return FALSE;
  103. }
  104. }
  105. Count = NewCount;
  106. return TRUE;
  107. }