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.

171 lines
3.7 KiB

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