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.

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