Leaked source code of windows server 2003
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.

187 lines
4.0 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. {
  42. void* tmp = realloc(pObj->m_pList,sizeof(DxDriverInfo)* pObj->m_nMax);
  43. if (tmp)
  44. pObj->m_pList=(DxDriverInfo*)tmp;
  45. else
  46. return FALSE;
  47. }
  48. else
  49. pObj->m_pList=(DxDriverInfo*)malloc(sizeof(DxDriverInfo)* pObj->m_nMax);
  50. if (pObj->m_pList==NULL)
  51. {
  52. pObj->m_bProblem=TRUE;
  53. return FALSE;
  54. }
  55. }
  56. USES_CONVERSION;
  57. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DxDriverInfo));
  58. pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)&guid);
  59. // pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)lpGuid);
  60. if (lpDriverDescription!=NULL) {
  61. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(lpDriverDescription);
  62. }
  63. if (lpDriverName!=NULL){
  64. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(lpDriverName);
  65. }
  66. pObj->m_nCount++;
  67. return TRUE;
  68. }
  69. C_dxj_DSEnumObject::C_dxj_DSEnumObject()
  70. {
  71. m_nMax=0;
  72. m_pList=NULL;
  73. m_nCount=0;
  74. m_bProblem=FALSE;
  75. }
  76. C_dxj_DSEnumObject::~C_dxj_DSEnumObject()
  77. {
  78. //empty list
  79. if (m_pList){
  80. for (int i=0;i<m_nCount;i++)
  81. {
  82. if (m_pList[i].strGuid) SysFreeString((BSTR)m_pList[i].strGuid);
  83. if (m_pList[i].strDescription) SysFreeString((BSTR)m_pList[i].strDescription);
  84. if (m_pList[i].strName) SysFreeString((BSTR)m_pList[i].strName);
  85. }
  86. free(m_pList);
  87. }
  88. }
  89. HRESULT C_dxj_DSEnumObject::create(DSOUNDENUMERATE pcbFunc,DSOUNDCAPTUREENUMERATE pcbFunc2,I_dxj_DSEnum **ppRet)
  90. {
  91. HRESULT hr=S_OK;
  92. C_dxj_DSEnumObject *pNew=NULL;
  93. //ASSERT(ppRet,"C_dxj_DSEnumObject::create passed invalid arg");
  94. *ppRet=NULL;
  95. pNew= new CComObject<C_dxj_DSEnumObject>;
  96. if (!pNew) return E_OUTOFMEMORY;
  97. pNew->m_bProblem=FALSE;
  98. if (pcbFunc)
  99. {
  100. hr=pcbFunc(objDirectSoundEnumCallback,pNew);
  101. }
  102. else if (pcbFunc2)
  103. {
  104. hr=pcbFunc2(objDirectSoundEnumCallback,pNew);
  105. }
  106. else {
  107. hr = E_INVALIDARG;
  108. }
  109. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  110. if FAILED(hr)
  111. {
  112. //let destructor do the clean up
  113. delete pNew;
  114. return hr;
  115. }
  116. hr=pNew->QueryInterface(IID_I_dxj_DSEnum,(void**)ppRet);
  117. return hr;
  118. }
  119. HRESULT C_dxj_DSEnumObject::getName( long index, BSTR *ret)
  120. {
  121. if (m_pList==NULL) return E_FAIL;
  122. if (index < 1) return E_INVALIDARG;
  123. if (index > m_nCount) return E_INVALIDARG;
  124. *ret=SysAllocString(m_pList[index-1].strName);
  125. return S_OK;
  126. }
  127. HRESULT C_dxj_DSEnumObject::getDescription( long index, BSTR *ret)
  128. {
  129. if (m_pList==NULL) return E_FAIL;
  130. if (index < 1) return E_INVALIDARG;
  131. if (index > m_nCount) return E_INVALIDARG;
  132. *ret=SysAllocString(m_pList[index-1].strDescription);
  133. return S_OK;
  134. }
  135. HRESULT C_dxj_DSEnumObject::getGuid( long index, BSTR *ret)
  136. {
  137. if (m_pList==NULL) return E_FAIL;
  138. if (index < 1) return E_INVALIDARG;
  139. if (index > m_nCount) return E_INVALIDARG;
  140. *ret=SysAllocString(m_pList[index-1].strGuid);
  141. return S_OK;
  142. }
  143. HRESULT C_dxj_DSEnumObject::getCount(long *retVal)
  144. {
  145. *retVal=m_nCount;
  146. return S_OK;
  147. }