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.

180 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dsenumobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define OLDDSENUM 1
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "dxglob7obj.h"
  15. #include "DSEnumObj.h"
  16. extern BSTR GUIDtoBSTR(LPGUID pGuid);
  17. extern "C" BOOL PASCAL objDirectSoundEnumCallback(
  18. #ifdef OLDDSENUM
  19. LPGUID lpGuid,
  20. #else
  21. LPCGUID lpGuid,
  22. #endif
  23. LPCSTR lpDriverDescription,
  24. LPCSTR lpDriverName,
  25. LPVOID lpArg
  26. )
  27. {
  28. GUID guid;
  29. ZeroMemory(&guid,sizeof(GUID));
  30. if (lpGuid){
  31. memcpy(&guid,lpGuid,sizeof(GUID));
  32. }
  33. DPF(1,"Entered objDirectDrawEnumCallback \r\n");
  34. C_dxj_DSEnumObject *pObj=(C_dxj_DSEnumObject*)lpArg;
  35. if (pObj==NULL) return TRUE;
  36. if (pObj->m_nCount >= pObj->m_nMax)
  37. {
  38. pObj->m_nMax += 10;
  39. if (pObj->m_pList)
  40. pObj->m_pList=(DXDRIVERINFO_CDESC*)realloc(pObj->m_pList,sizeof(DXDRIVERINFO_CDESC)* pObj->m_nMax);
  41. else
  42. pObj->m_pList=(DXDRIVERINFO_CDESC*)malloc(sizeof(DXDRIVERINFO_CDESC)* pObj->m_nMax);
  43. if (pObj->m_pList==NULL)
  44. {
  45. pObj->m_bProblem=TRUE;
  46. return FALSE;
  47. }
  48. }
  49. USES_CONVERSION;
  50. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DXDRIVERINFO_CDESC));
  51. pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)&guid);
  52. // pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)lpGuid);
  53. if (lpDriverDescription!=NULL) {
  54. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(lpDriverDescription);
  55. }
  56. if (lpDriverName!=NULL){
  57. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(lpDriverName);
  58. }
  59. pObj->m_nCount++;
  60. return TRUE;
  61. }
  62. C_dxj_DSEnumObject::C_dxj_DSEnumObject()
  63. {
  64. m_nMax=0;
  65. m_pList=NULL;
  66. m_nCount=0;
  67. m_bProblem=FALSE;
  68. }
  69. C_dxj_DSEnumObject::~C_dxj_DSEnumObject()
  70. {
  71. //empty list
  72. if (m_pList){
  73. for (int i=0;i<m_nCount;i++)
  74. {
  75. if (m_pList[i].strGuid) SysFreeString(m_pList[i].strGuid);
  76. if (m_pList[i].strDescription) SysFreeString(m_pList[i].strDescription);
  77. if (m_pList[i].strName) SysFreeString(m_pList[i].strName);
  78. }
  79. free(m_pList);
  80. }
  81. }
  82. HRESULT C_dxj_DSEnumObject::create(DSOUNDENUMERATE pcbFunc,DSOUNDCAPTUREENUMERATE pcbFunc2,I_dxj_DSEnum **ppRet)
  83. {
  84. HRESULT hr=S_OK;
  85. C_dxj_DSEnumObject *pNew=NULL;
  86. //ASSERT(ppRet,"C_dxj_DSEnumObject::create passed invalid arg");
  87. *ppRet=NULL;
  88. pNew= new CComObject<C_dxj_DSEnumObject>;
  89. if (!pNew) return E_OUTOFMEMORY;
  90. pNew->m_bProblem=FALSE;
  91. if (pcbFunc)
  92. {
  93. hr=pcbFunc(objDirectSoundEnumCallback,pNew);
  94. }
  95. else if (pcbFunc2)
  96. {
  97. hr=pcbFunc2(objDirectSoundEnumCallback,pNew);
  98. }
  99. else {
  100. hr = E_INVALIDARG;
  101. }
  102. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  103. if FAILED(hr)
  104. {
  105. //let destructor do the clean up
  106. delete pNew;
  107. return hr;
  108. }
  109. hr=pNew->QueryInterface(IID_I_dxj_DSEnum,(void**)ppRet);
  110. return hr;
  111. }
  112. HRESULT C_dxj_DSEnumObject::getName( long index, BSTR *ret)
  113. {
  114. if (m_pList==NULL) return E_FAIL;
  115. if (index < 1) return E_INVALIDARG;
  116. if (index > m_nCount) return E_INVALIDARG;
  117. *ret=SysAllocString(m_pList[index-1].strName);
  118. return S_OK;
  119. }
  120. HRESULT C_dxj_DSEnumObject::getDescription( long index, BSTR *ret)
  121. {
  122. if (m_pList==NULL) return E_FAIL;
  123. if (index < 1) return E_INVALIDARG;
  124. if (index > m_nCount) return E_INVALIDARG;
  125. *ret=SysAllocString(m_pList[index-1].strDescription);
  126. return S_OK;
  127. }
  128. HRESULT C_dxj_DSEnumObject::getGuid( long index, BSTR *ret)
  129. {
  130. if (m_pList==NULL) return E_FAIL;
  131. if (index < 1) return E_INVALIDARG;
  132. if (index > m_nCount) return E_INVALIDARG;
  133. *ret=SysAllocString(m_pList[index-1].strGuid);
  134. return S_OK;
  135. }
  136. HRESULT C_dxj_DSEnumObject::getCount(long *retVal)
  137. {
  138. *retVal=m_nCount;
  139. return S_OK;
  140. }