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.

163 lines
2.8 KiB

  1. #include "procs.hxx"
  2. #pragma hdrstop
  3. #include "oleds.hxx"
  4. extern PROUTER_ENTRY g_pRouterHead;
  5. extern CRITICAL_SECTION g_csRouterHeadCritSect;
  6. CEnumVariant::CEnumVariant()
  7. {
  8. _cRef = 1;
  9. //
  10. // Make sure the router has been initialized
  11. //
  12. EnterCriticalSection(&g_csRouterHeadCritSect);
  13. if (!g_pRouterHead) {
  14. g_pRouterHead = InitializeRouter();
  15. }
  16. LeaveCriticalSection(&g_csRouterHeadCritSect);
  17. _lpCurrentRouterEntry = g_pRouterHead;
  18. }
  19. CEnumVariant::~CEnumVariant()
  20. {
  21. }
  22. HRESULT
  23. CEnumVariant::Create(IEnumVARIANT **ppenum)
  24. {
  25. HRESULT hr;
  26. CEnumVariant * pEnum;
  27. pEnum = new CEnumVariant();
  28. if (!pEnum) {
  29. RRETURN (E_OUTOFMEMORY);
  30. }
  31. if (pEnum)
  32. {
  33. hr = pEnum->QueryInterface(IID_IEnumVARIANT,
  34. (void **)ppenum);
  35. pEnum->Release();
  36. }
  37. else
  38. {
  39. *ppenum = NULL;
  40. RRETURN(E_OUTOFMEMORY);
  41. }
  42. RRETURN(hr);
  43. }
  44. STDMETHODIMP
  45. CEnumVariant::QueryInterface(REFIID iid, void FAR* FAR* ppv)
  46. {
  47. *ppv = NULL;
  48. if (iid == IID_IUnknown || iid == IID_IEnumVARIANT) {
  49. *ppv = this;
  50. }
  51. else {
  52. return ResultFromScode(E_NOINTERFACE);
  53. }
  54. AddRef();
  55. return NOERROR;
  56. }
  57. STDMETHODIMP_(ULONG)
  58. CEnumVariant::AddRef(void)
  59. {
  60. return ++_cRef;
  61. }
  62. STDMETHODIMP_(ULONG)
  63. CEnumVariant::Release(void)
  64. {
  65. if(--_cRef == 0){
  66. delete this;
  67. return 0;
  68. }
  69. return _cRef;
  70. }
  71. STDMETHODIMP
  72. CEnumVariant::Next(ULONG cElements, VARIANT FAR* pvar, ULONG FAR* pcElementFetched)
  73. {
  74. DWORD dwFound = 0;
  75. PROUTER_ENTRY lpRouter = _lpCurrentRouterEntry;
  76. HRESULT hr;
  77. IDispatch * lpDispatch;
  78. while (lpRouter && (dwFound < cElements)) {
  79. hr = CoCreateInstance(*lpRouter->pNamespaceClsid,
  80. NULL,
  81. CLSCTX_INPROC_SERVER,
  82. IID_IDispatch,
  83. (void **)&lpDispatch
  84. );
  85. if (FAILED(hr)) {
  86. lpRouter = lpRouter->pNext;
  87. continue;
  88. }
  89. VariantInit(&pvar[dwFound]);
  90. pvar[dwFound].vt = VT_DISPATCH;
  91. pvar[dwFound].punkVal = lpDispatch;
  92. dwFound++;
  93. lpRouter = lpRouter->pNext;
  94. }
  95. _lpCurrentRouterEntry = lpRouter;
  96. //
  97. // Hack for VB -- it passes NULL always
  98. //
  99. if (pcElementFetched) {
  100. *pcElementFetched = dwFound;
  101. }
  102. if (dwFound < cElements) {
  103. RRETURN(S_FALSE);
  104. }
  105. RRETURN(S_OK);
  106. }
  107. STDMETHODIMP
  108. CEnumVariant::Skip(ULONG cElements)
  109. {
  110. RRETURN(ResultFromScode(E_FAIL));
  111. }
  112. STDMETHODIMP
  113. CEnumVariant::Reset()
  114. {
  115. RRETURN(ResultFromScode(S_OK));
  116. }
  117. STDMETHODIMP
  118. CEnumVariant::Clone(IEnumVARIANT FAR* FAR* ppenum)
  119. {
  120. RRETURN(ResultFromScode(E_FAIL));
  121. }