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.

195 lines
4.4 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. pObj->m_pList=(DxDriverInfo*)realloc(pObj->m_pList,sizeof(DxDriverInfo)* pObj->m_nMax);
  29. else
  30. pObj->m_pList=(DxDriverInfo*)malloc(sizeof(DxDriverInfo)* pObj->m_nMax);
  31. if (pObj->m_pListHW)
  32. pObj->m_pListHW=(D3DDEVICEDESC7*)realloc(pObj->m_pListHW,sizeof(D3DDEVICEDESC7)* pObj->m_nMax);
  33. else
  34. pObj->m_pListHW=(D3DDEVICEDESC7*)malloc(sizeof(D3DDEVICEDESC7)* pObj->m_nMax);
  35. }
  36. //Fix for Whistler 45161
  37. //NOTE no way to get out of memory error back to user.
  38. //so we just return what we can.
  39. if (!pObj->m_pList) return D3DENUMRET_CANCEL;
  40. if (!pObj->m_pListHW)
  41. {
  42. free(pObj->m_pList);
  43. return D3DENUMRET_CANCEL;
  44. }
  45. USES_CONVERSION;
  46. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DxDriverInfo));
  47. pObj->m_pList[pObj->m_nCount].strGuid=D3DGUIDtoBSTR(&(lpD3DDevDesc->deviceGUID));
  48. if (DevDesc!=NULL) {
  49. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(DevDesc);
  50. }
  51. if (DevName!=NULL){
  52. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(DevName);
  53. }
  54. ZeroMemory(&(pObj->m_pListHW[pObj->m_nCount]),sizeof(D3DDEVICEDESC7));
  55. if (lpD3DDevDesc){
  56. memcpy(&(pObj->m_pListHW[pObj->m_nCount]),lpD3DDevDesc,sizeof(D3DDEVICEDESC7));
  57. }
  58. pObj->m_nCount++;
  59. return D3DENUMRET_OK;
  60. }
  61. C_dxj_Direct3DEnumDevices7Object::C_dxj_Direct3DEnumDevices7Object()
  62. {
  63. m_nMax=0;
  64. m_pList=NULL;
  65. m_pListHW=NULL;
  66. m_nCount=0;
  67. m_bProblem=FALSE;
  68. }
  69. C_dxj_Direct3DEnumDevices7Object::~C_dxj_Direct3DEnumDevices7Object()
  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_Direct3DEnumDevices7Object::create(LPDIRECT3D7 pD3D,I_dxj_Direct3DEnumDevices **ppRet)
  83. {
  84. HRESULT hr;
  85. C_dxj_Direct3DEnumDevices7Object *pNew=NULL;
  86. *ppRet=NULL;
  87. pNew= new CComObject<C_dxj_Direct3DEnumDevices7Object>;
  88. if (!pNew) return E_OUTOFMEMORY;
  89. pNew->m_bProblem=FALSE;
  90. hr=pD3D->EnumDevices(objEnumDevices7Callback, (void*)pNew);
  91. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  92. if FAILED(hr)
  93. {
  94. if (pNew->m_pList) free(pNew->m_pList);
  95. if (pNew->m_pListHW) free(pNew->m_pListHW);
  96. delete pNew;
  97. return hr;
  98. }
  99. hr=pNew->QueryInterface(IID_I_dxj_Direct3DEnumDevices,(void**)ppRet);
  100. return hr;
  101. }
  102. HRESULT C_dxj_Direct3DEnumDevices7Object::getGuid( long index, BSTR *info)
  103. {
  104. if (m_pList==NULL) return E_FAIL;
  105. if (index < 1) return E_INVALIDARG;
  106. if (index > m_nCount) return E_INVALIDARG;
  107. if (!info) return E_INVALIDARG;
  108. *info=SysAllocString(m_pList[index-1].strGuid);
  109. return S_OK;
  110. }
  111. HRESULT C_dxj_Direct3DEnumDevices7Object::getName( long index, BSTR *info)
  112. {
  113. if (m_pList==NULL) return E_FAIL;
  114. if (index < 1) return E_INVALIDARG;
  115. if (index > m_nCount) return E_INVALIDARG;
  116. if (!info) return E_INVALIDARG;
  117. *info=SysAllocString(m_pList[index-1].strName);
  118. return S_OK;
  119. }
  120. HRESULT C_dxj_Direct3DEnumDevices7Object::getDescription( long index, BSTR *info)
  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. if (!info) return E_INVALIDARG;
  126. *info=SysAllocString(m_pList[index-1].strDescription);
  127. return S_OK;
  128. }
  129. HRESULT C_dxj_Direct3DEnumDevices7Object::getCount(long *retVal)
  130. {
  131. *retVal=m_nCount;
  132. return S_OK;
  133. }
  134. HRESULT C_dxj_Direct3DEnumDevices7Object::getDesc(long index, D3dDeviceDesc7 *desc)
  135. {
  136. if (m_pListHW==NULL) return E_FAIL;
  137. if (index < 1) return E_INVALIDARG;
  138. if (index > m_nCount) return E_INVALIDARG;
  139. memcpy(desc,&(m_pListHW[index-1]),sizeof(D3dDeviceDesc7));
  140. return S_OK;
  141. }