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.

131 lines
2.7 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. #include <windows.h>
  3. #include "guidenum.h"
  4. //
  5. // implementation of the enumerator returned by DMO enumeration API
  6. //
  7. CEnumDMOCLSID::CEnumDMOCLSID() {
  8. m_cRef = 1;
  9. m_ulPos = 0;
  10. }
  11. CEnumDMOCLSID::~CEnumDMOCLSID() {
  12. Entry* pEntry;
  13. DWORD ulPos = 0;
  14. while (pEntry = m_store.GetNth(ulPos)) {
  15. delete [] pEntry->szName;
  16. ulPos++;
  17. }
  18. }
  19. HRESULT CEnumDMOCLSID::QueryInterface(REFIID riid, void **ppv) {
  20. if (NULL == ppv) {
  21. return E_POINTER;
  22. }
  23. if (riid == IID_IUnknown) {
  24. AddRef();
  25. *ppv = (IUnknown*)this;
  26. return NOERROR;
  27. }
  28. else if (riid == IID_IEnumDMO) {
  29. AddRef();
  30. *ppv = (IEnumDMO*)this;
  31. return NOERROR;
  32. }
  33. else
  34. return E_NOINTERFACE;
  35. }
  36. ULONG CEnumDMOCLSID::AddRef() {
  37. return InterlockedIncrement((long*)&m_cRef);
  38. }
  39. ULONG CEnumDMOCLSID::Release() {
  40. long l = InterlockedDecrement((long*)&m_cRef);
  41. if (l == 0) {
  42. delete this;
  43. }
  44. return l;
  45. }
  46. HRESULT CEnumDMOCLSID::Next(ULONG celt, CLSID *pCLSIDs, WCHAR **pszNames, ULONG *pceltFetched) {
  47. if( NULL == pCLSIDs ) {
  48. return E_POINTER;
  49. }
  50. if( (1 != celt) && (NULL == pceltFetched) ) {
  51. return E_INVALIDARG;
  52. }
  53. for (ULONG c = 0; c < celt; c++) {
  54. Entry* p = m_store.GetNth(m_ulPos + c);
  55. if (!p)
  56. break;
  57. pCLSIDs[c] = p->clsid;
  58. WCHAR* szSrc = p->szName;
  59. if (!szSrc)
  60. szSrc = L"";
  61. if (pszNames) {
  62. pszNames[c] = (WCHAR*) CoTaskMemAlloc(sizeof(WCHAR) * (wcslen(szSrc) + 1));
  63. if (pszNames[c]) {
  64. wcscpy(pszNames[c], szSrc);
  65. } else {
  66. for (ULONG c1 = 0; c1 < c; c1++) {
  67. CoTaskMemFree(pszNames[c1]);
  68. pszNames[c1] = NULL;
  69. }
  70. return E_OUTOFMEMORY;
  71. }
  72. }
  73. }
  74. if( NULL != pceltFetched ) {
  75. *pceltFetched = c;
  76. }
  77. m_ulPos += c;
  78. return (c == celt) ? S_OK : S_FALSE;
  79. }
  80. HRESULT CEnumDMOCLSID::Skip(ULONG celt) {
  81. m_ulPos += celt;
  82. // The documentation for IEnumXXXX::Skip() states that
  83. // it returns "S_OK if the number of elements skipped
  84. // is celt; otherwise S_FALSE." (MSDN Library April 2000).
  85. if( m_ulPos <= m_store.GetSize() ) {
  86. return S_OK;
  87. } else {
  88. return S_FALSE;
  89. }
  90. }
  91. HRESULT CEnumDMOCLSID::Reset(void) {
  92. m_ulPos = 0;
  93. return NOERROR;
  94. }
  95. HRESULT CEnumDMOCLSID::Clone(IEnumDMO ** ppenum) {
  96. return E_NOTIMPL;
  97. }
  98. void CEnumDMOCLSID::Add(REFCLSID clsidDMO, WCHAR* szName) {
  99. WCHAR *szNm = NULL;
  100. if (szName) {
  101. szNm = new WCHAR[wcslen(szName) + 1];
  102. if (szNm) {
  103. wcscpy(szNm, szName);
  104. } else {
  105. return;
  106. }
  107. }
  108. Entry e;
  109. e.clsid = clsidDMO;
  110. e.szName = szNm;
  111. m_store.Add(e);
  112. }