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.1 KiB

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