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.

180 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ddenummodesobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DDEnumModesObj.h"
  14. extern BOOL IsAllZeros(void *pStruct,DWORD size);
  15. extern "C" HRESULT PASCAL objEnumModes2Callback(LPDDSURFACEDESC2 lpDesc, void *lpArg)
  16. {
  17. DPF(1,"Entered objEnumModes2Callback\r\n");
  18. C_dxj_DirectDrawEnumModesObject *pObj=(C_dxj_DirectDrawEnumModesObject*)lpArg;
  19. if (pObj==NULL) return DDENUMRET_OK;
  20. if (pObj->m_nCount >= pObj->m_nMax)
  21. {
  22. pObj->m_nMax += 10;
  23. if (pObj->m_pList)
  24. pObj->m_pList=(DDSurfaceDesc2*)realloc(pObj->m_pList,sizeof(DDSurfaceDesc2)* pObj->m_nMax);
  25. else
  26. pObj->m_pList=(DDSurfaceDesc2*)malloc(sizeof(DDSurfaceDesc2)* pObj->m_nMax);
  27. if (pObj->m_pList==NULL)
  28. {
  29. pObj->m_bProblem=TRUE;
  30. return FALSE;
  31. }
  32. }
  33. if (lpDesc==NULL) {
  34. pObj->m_bProblem=TRUE;
  35. return FALSE;
  36. }
  37. HRESULT hr=CopyOutDDSurfaceDesc2(&(pObj->m_pList[pObj->m_nCount]),lpDesc);
  38. if (FAILED(hr)){
  39. pObj->m_bProblem=TRUE;
  40. return FALSE;
  41. }
  42. pObj->m_nCount++;
  43. return TRUE;
  44. }
  45. C_dxj_DirectDrawEnumModesObject::C_dxj_DirectDrawEnumModesObject()
  46. {
  47. m_nMax=0;
  48. m_pList=NULL;
  49. m_nCount=0;
  50. m_bProblem=FALSE;
  51. }
  52. C_dxj_DirectDrawEnumModesObject::~C_dxj_DirectDrawEnumModesObject()
  53. {
  54. //empty list
  55. if (m_pList){
  56. free(m_pList);
  57. }
  58. }
  59. HRESULT C_dxj_DirectDrawEnumModesObject::create(LPDIRECTDRAW7 pdd, long flags, DDSurfaceDesc2 *desc, I_dxj_DirectDrawEnumModes **ppRet)
  60. {
  61. HRESULT hr;
  62. C_dxj_DirectDrawEnumModesObject *pNew=NULL;
  63. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  64. *ppRet=NULL;
  65. if (!pdd) return E_INVALIDARG;
  66. pNew= new CComObject<C_dxj_DirectDrawEnumModesObject>;
  67. if (!pNew) return E_OUTOFMEMORY;
  68. pNew->m_bProblem=FALSE;
  69. //note DDSurfaceDesc as a DDSURFACEDESC structure inside it.
  70. if ((desc==NULL)|| (IsAllZeros(desc,sizeof(DDSurfaceDesc2)))) {
  71. hr=pdd->EnumDisplayModes((DWORD)flags,NULL,pNew,objEnumModes2Callback);
  72. }
  73. else {
  74. DDSURFACEDESC2 desc2;
  75. hr=CopyInDDSurfaceDesc2(&desc2,desc);
  76. if (hr==S_OK){
  77. hr=pdd->EnumDisplayModes((DWORD)flags,&desc2,pNew,objEnumModes2Callback);
  78. }
  79. }
  80. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  81. if FAILED(hr)
  82. {
  83. free(pNew->m_pList);
  84. pNew->m_pList=NULL;
  85. delete pNew;
  86. return hr;
  87. }
  88. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumModes,(void**)ppRet);
  89. return hr;
  90. }
  91. HRESULT C_dxj_DirectDrawEnumModesObject::create(LPDIRECTDRAW4 pdd, long flags, DDSurfaceDesc2 *desc, I_dxj_DirectDrawEnumModes **ppRet)
  92. {
  93. HRESULT hr;
  94. C_dxj_DirectDrawEnumModesObject *pNew=NULL;
  95. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  96. *ppRet=NULL;
  97. if (!pdd) return E_INVALIDARG;
  98. pNew= new CComObject<C_dxj_DirectDrawEnumModesObject>;
  99. if (!pNew) return E_OUTOFMEMORY;
  100. pNew->m_bProblem=FALSE;
  101. //note DDSurfaceDesc as a DDSURFACEDESC structure inside it.
  102. if ((desc==NULL)|| (IsAllZeros(desc,sizeof(DDSurfaceDesc2)))) {
  103. hr=pdd->EnumDisplayModes((DWORD)flags,NULL,pNew,objEnumModes2Callback);
  104. }
  105. else {
  106. DDSURFACEDESC2 desc2;
  107. hr=CopyInDDSurfaceDesc2(&desc2,desc);
  108. if (hr==S_OK){
  109. hr=pdd->EnumDisplayModes((DWORD)flags,&desc2,pNew,objEnumModes2Callback);
  110. }
  111. }
  112. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  113. if FAILED(hr)
  114. {
  115. free(pNew->m_pList);
  116. pNew->m_pList=NULL;
  117. delete pNew;
  118. return hr;
  119. }
  120. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumModes,(void**)ppRet);
  121. return hr;
  122. }
  123. HRESULT C_dxj_DirectDrawEnumModesObject::getItem( long index, DDSurfaceDesc2 *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. memcpy(info,&(m_pList[index-1]),sizeof(DDSurfaceDesc2));
  129. return S_OK;
  130. }
  131. HRESULT C_dxj_DirectDrawEnumModesObject::getCount(long *retVal)
  132. {
  133. *retVal=m_nCount;
  134. return S_OK;
  135. }