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.2 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. {
  25. void* tmp = realloc(pObj->m_pList,sizeof(DDSurfaceDesc2)* pObj->m_nMax);
  26. if (tmp)
  27. pObj->m_pList=(DDSurfaceDesc2*)tmp;
  28. else
  29. return DDENUMRET_CANCEL;
  30. }
  31. else
  32. pObj->m_pList=(DDSurfaceDesc2*)malloc(sizeof(DDSurfaceDesc2)* pObj->m_nMax);
  33. if (pObj->m_pList==NULL)
  34. {
  35. pObj->m_bProblem=TRUE;
  36. return FALSE;
  37. }
  38. }
  39. if (lpDesc==NULL) {
  40. pObj->m_bProblem=TRUE;
  41. return FALSE;
  42. }
  43. HRESULT hr=CopyOutDDSurfaceDesc2(&(pObj->m_pList[pObj->m_nCount]),lpDesc);
  44. if (FAILED(hr)){
  45. pObj->m_bProblem=TRUE;
  46. return FALSE;
  47. }
  48. pObj->m_nCount++;
  49. return TRUE;
  50. }
  51. C_dxj_DirectDrawEnumModesObject::C_dxj_DirectDrawEnumModesObject()
  52. {
  53. m_nMax=0;
  54. m_pList=NULL;
  55. m_nCount=0;
  56. m_bProblem=FALSE;
  57. }
  58. C_dxj_DirectDrawEnumModesObject::~C_dxj_DirectDrawEnumModesObject()
  59. {
  60. //empty list
  61. if (m_pList){
  62. free(m_pList);
  63. }
  64. }
  65. HRESULT C_dxj_DirectDrawEnumModesObject::create(LPDIRECTDRAW7 pdd, long flags, DDSurfaceDesc2 *desc, I_dxj_DirectDrawEnumModes **ppRet)
  66. {
  67. HRESULT hr;
  68. C_dxj_DirectDrawEnumModesObject *pNew=NULL;
  69. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  70. *ppRet=NULL;
  71. if (!pdd) return E_INVALIDARG;
  72. pNew= new CComObject<C_dxj_DirectDrawEnumModesObject>;
  73. if (!pNew) return E_OUTOFMEMORY;
  74. pNew->m_bProblem=FALSE;
  75. //note DDSurfaceDesc as a DDSURFACEDESC structure inside it.
  76. if ((desc==NULL)|| (IsAllZeros(desc,sizeof(DDSurfaceDesc2)))) {
  77. hr=pdd->EnumDisplayModes((DWORD)flags,NULL,pNew,objEnumModes2Callback);
  78. }
  79. else {
  80. DDSURFACEDESC2 desc2;
  81. hr=CopyInDDSurfaceDesc2(&desc2,desc);
  82. if (hr==S_OK){
  83. hr=pdd->EnumDisplayModes((DWORD)flags,&desc2,pNew,objEnumModes2Callback);
  84. }
  85. }
  86. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  87. if FAILED(hr)
  88. {
  89. free(pNew->m_pList);
  90. pNew->m_pList=NULL;
  91. delete pNew;
  92. return hr;
  93. }
  94. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumModes,(void**)ppRet);
  95. return hr;
  96. }
  97. HRESULT C_dxj_DirectDrawEnumModesObject::create(LPDIRECTDRAW4 pdd, long flags, DDSurfaceDesc2 *desc, I_dxj_DirectDrawEnumModes **ppRet)
  98. {
  99. HRESULT hr;
  100. C_dxj_DirectDrawEnumModesObject *pNew=NULL;
  101. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  102. *ppRet=NULL;
  103. if (!pdd) return E_INVALIDARG;
  104. pNew= new CComObject<C_dxj_DirectDrawEnumModesObject>;
  105. if (!pNew) return E_OUTOFMEMORY;
  106. pNew->m_bProblem=FALSE;
  107. //note DDSurfaceDesc as a DDSURFACEDESC structure inside it.
  108. if ((desc==NULL)|| (IsAllZeros(desc,sizeof(DDSurfaceDesc2)))) {
  109. hr=pdd->EnumDisplayModes((DWORD)flags,NULL,pNew,objEnumModes2Callback);
  110. }
  111. else {
  112. DDSURFACEDESC2 desc2;
  113. hr=CopyInDDSurfaceDesc2(&desc2,desc);
  114. if (hr==S_OK){
  115. hr=pdd->EnumDisplayModes((DWORD)flags,&desc2,pNew,objEnumModes2Callback);
  116. }
  117. }
  118. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  119. if FAILED(hr)
  120. {
  121. free(pNew->m_pList);
  122. pNew->m_pList=NULL;
  123. delete pNew;
  124. return hr;
  125. }
  126. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumModes,(void**)ppRet);
  127. return hr;
  128. }
  129. HRESULT C_dxj_DirectDrawEnumModesObject::getItem( long index, DDSurfaceDesc2 *info)
  130. {
  131. if (m_pList==NULL) return E_FAIL;
  132. if (index < 1) return E_INVALIDARG;
  133. if (index > m_nCount) return E_INVALIDARG;
  134. memcpy(info,&(m_pList[index-1]),sizeof(DDSurfaceDesc2));
  135. return S_OK;
  136. }
  137. HRESULT C_dxj_DirectDrawEnumModesObject::getCount(long *retVal)
  138. {
  139. *retVal=m_nCount;
  140. return S_OK;
  141. }