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.

207 lines
4.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3denumdevices7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "D3DEnumDevices7Obj.h"
  14. extern BSTR D3DGUIDtoBSTR(LPGUID pGuid);
  15. /////////////////////////////////////////////////////////////////////////////
  16. extern "C" HRESULT PASCAL objEnumDevices7Callback(
  17. LPSTR DevDesc,
  18. LPSTR DevName,
  19. LPD3DDEVICEDESC7 lpD3DDevDesc,
  20. void *lpArg)
  21. {
  22. C_dxj_Direct3DEnumDevices7Object *pObj=(C_dxj_Direct3DEnumDevices7Object*)lpArg;
  23. if (pObj==NULL) return D3DENUMRET_OK;
  24. if (pObj->m_nCount >= pObj->m_nMax)
  25. {
  26. pObj->m_nMax += 10;
  27. if (pObj->m_pList)
  28. {
  29. void* tmp = realloc(pObj->m_pList,sizeof(DxDriverInfo)* pObj->m_nMax);
  30. if (tmp != NULL)
  31. pObj->m_pList = (DxDriverInfo*)tmp;
  32. else
  33. return D3DENUMRET_CANCEL;
  34. }
  35. else
  36. pObj->m_pList=(DxDriverInfo*)malloc(sizeof(DxDriverInfo)* pObj->m_nMax);
  37. if (pObj->m_pListHW)
  38. {
  39. void* tmpHw = realloc(pObj->m_pListHW,sizeof(D3DDEVICEDESC7)* pObj->m_nMax);
  40. if (tmpHw)
  41. pObj->m_pListHW = (D3DDEVICEDESC7*)tmpHw;
  42. else
  43. return D3DENUMRET_CANCEL;
  44. }
  45. else
  46. pObj->m_pListHW=(D3DDEVICEDESC7*)malloc(sizeof(D3DDEVICEDESC7)* pObj->m_nMax);
  47. }
  48. //Fix for Whistler 45161
  49. //NOTE no way to get out of memory error back to user.
  50. //so we just return what we can.
  51. if (!pObj->m_pList) return D3DENUMRET_CANCEL;
  52. if (!pObj->m_pListHW)
  53. {
  54. free(pObj->m_pList);
  55. return D3DENUMRET_CANCEL;
  56. }
  57. USES_CONVERSION;
  58. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DxDriverInfo));
  59. pObj->m_pList[pObj->m_nCount].strGuid=D3DGUIDtoBSTR(&(lpD3DDevDesc->deviceGUID));
  60. if (DevDesc!=NULL) {
  61. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(DevDesc);
  62. }
  63. if (DevName!=NULL){
  64. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(DevName);
  65. }
  66. ZeroMemory(&(pObj->m_pListHW[pObj->m_nCount]),sizeof(D3DDEVICEDESC7));
  67. if (lpD3DDevDesc){
  68. memcpy(&(pObj->m_pListHW[pObj->m_nCount]),lpD3DDevDesc,sizeof(D3DDEVICEDESC7));
  69. }
  70. pObj->m_nCount++;
  71. return D3DENUMRET_OK;
  72. }
  73. C_dxj_Direct3DEnumDevices7Object::C_dxj_Direct3DEnumDevices7Object()
  74. {
  75. m_nMax=0;
  76. m_pList=NULL;
  77. m_pListHW=NULL;
  78. m_nCount=0;
  79. m_bProblem=FALSE;
  80. }
  81. C_dxj_Direct3DEnumDevices7Object::~C_dxj_Direct3DEnumDevices7Object()
  82. {
  83. //empty list
  84. if (m_pList){
  85. for (int i=0;i<m_nCount;i++)
  86. {
  87. if (m_pList[i].strGuid) SysFreeString((BSTR)m_pList[i].strGuid);
  88. if (m_pList[i].strDescription) SysFreeString((BSTR)m_pList[i].strDescription);
  89. if (m_pList[i].strName) SysFreeString((BSTR)m_pList[i].strName);
  90. }
  91. free(m_pList);
  92. }
  93. }
  94. HRESULT C_dxj_Direct3DEnumDevices7Object::create(LPDIRECT3D7 pD3D,I_dxj_Direct3DEnumDevices **ppRet)
  95. {
  96. HRESULT hr;
  97. C_dxj_Direct3DEnumDevices7Object *pNew=NULL;
  98. *ppRet=NULL;
  99. pNew= new CComObject<C_dxj_Direct3DEnumDevices7Object>;
  100. if (!pNew) return E_OUTOFMEMORY;
  101. pNew->m_bProblem=FALSE;
  102. hr=pD3D->EnumDevices(objEnumDevices7Callback, (void*)pNew);
  103. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  104. if FAILED(hr)
  105. {
  106. if (pNew->m_pList) free(pNew->m_pList);
  107. if (pNew->m_pListHW) free(pNew->m_pListHW);
  108. delete pNew;
  109. return hr;
  110. }
  111. hr=pNew->QueryInterface(IID_I_dxj_Direct3DEnumDevices,(void**)ppRet);
  112. return hr;
  113. }
  114. HRESULT C_dxj_Direct3DEnumDevices7Object::getGuid( long index, BSTR *info)
  115. {
  116. if (m_pList==NULL) return E_FAIL;
  117. if (index < 1) return E_INVALIDARG;
  118. if (index > m_nCount) return E_INVALIDARG;
  119. if (!info) return E_INVALIDARG;
  120. *info=SysAllocString(m_pList[index-1].strGuid);
  121. return S_OK;
  122. }
  123. HRESULT C_dxj_Direct3DEnumDevices7Object::getName( long index, BSTR *info)
  124. {
  125. if (m_pList==NULL) return E_FAIL;
  126. if (index < 1) return E_INVALIDARG;
  127. if (index > m_nCount) return E_INVALIDARG;
  128. if (!info) return E_INVALIDARG;
  129. *info=SysAllocString(m_pList[index-1].strName);
  130. return S_OK;
  131. }
  132. HRESULT C_dxj_Direct3DEnumDevices7Object::getDescription( long index, BSTR *info)
  133. {
  134. if (m_pList==NULL) return E_FAIL;
  135. if (index < 1) return E_INVALIDARG;
  136. if (index > m_nCount) return E_INVALIDARG;
  137. if (!info) return E_INVALIDARG;
  138. *info=SysAllocString(m_pList[index-1].strDescription);
  139. return S_OK;
  140. }
  141. HRESULT C_dxj_Direct3DEnumDevices7Object::getCount(long *retVal)
  142. {
  143. *retVal=m_nCount;
  144. return S_OK;
  145. }
  146. HRESULT C_dxj_Direct3DEnumDevices7Object::getDesc(long index, D3dDeviceDesc7 *desc)
  147. {
  148. if (m_pListHW==NULL) return E_FAIL;
  149. if (index < 1) return E_INVALIDARG;
  150. if (index > m_nCount) return E_INVALIDARG;
  151. memcpy(desc,&(m_pListHW[index-1]),sizeof(D3dDeviceDesc7));
  152. return S_OK;
  153. }