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.

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