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.

131 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: ddenumplayersobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxglobobj.h"
  14. #include "DDEnumObj.h"
  15. extern "C" BSTR GUIDtoBSTR(LPGUID pGuid);
  16. extern "C" BOOL PASCAL objDirectDrawEnumCallback(
  17. GUID FAR *lpGUID,
  18. LPSTR lpDriverDescription,
  19. LPSTR lpDriverName,
  20. LPVOID lpArg
  21. )
  22. {
  23. #ifdef _DEBUG
  24. OutputDebugString("Entered objDirectDrawEnumCallback \r\n");
  25. #endif
  26. C_dxj_DDEnumObject *pObj=(C_dxj_DDEnumObject*)lpArg;
  27. if (pObj==NULL) return DDENUMRET_OK;
  28. if (pObj->m_nCount >= pObj->m_nMax)
  29. {
  30. pObj->m_nMax += 10;
  31. pObj->m_pList=(DxDriverInfo*)realloc(pObj->m_pList,sizeof(DxDriverInfo)* pObj->m_nMax);
  32. if (pObj->m_pList==NULL)
  33. {
  34. pObj->m_bProblem=TRUE;
  35. return FALSE;
  36. }
  37. }
  38. USES_CONVERSION;
  39. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DxDriverInfo));
  40. pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)lpGUID);
  41. if (lpDriverDescription!=NULL) {
  42. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(lpDriverDescription);
  43. }
  44. if (lpDriverName!=NULL){
  45. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(lpDriverName);
  46. }
  47. pObj->m_nCount++;
  48. return TRUE;
  49. }
  50. C_dxj_DDEnumObject::C_dxj_DDEnumObject()
  51. {
  52. m_nMax=0;
  53. m_pList=NULL;
  54. m_nCount=0;
  55. m_bProblem=FALSE;
  56. }
  57. C_dxj_DDEnumObject::~C_dxj_DDEnumObject()
  58. {
  59. //empty list
  60. if (m_pList){
  61. for (int i=0;i<m_nCount;i++)
  62. {
  63. if (m_pList[i].guid) SysFreeString(m_pList[i].strGuid);
  64. if (m_pList[i].description) SysFreeString(m_pList[i].strDescription);
  65. if (m_pList[i].name) SysFreeString(m_pList[i].strName);
  66. }
  67. free(m_pList);
  68. }
  69. }
  70. HRESULT C_dxj_DDEnumObject::create(DDENUMERATE pcbFunc,I_dxj_DDEnum **ppRet)
  71. {
  72. HRESULT hr;
  73. C_dxj_DDEnumObject *pNew=NULL;
  74. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  75. *ppRet=NULL;
  76. pNew= new CComObject<C_dxj_DDEnumObject>;
  77. if (!pNew) return E_OUTOFMEMORY;
  78. pNew->m_bProblem=FALSE;
  79. hr=pcbFunc(objDirectDrawEnumCallback,(void*)pNew);
  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_DDEnum,(void**)ppRet);
  89. return hr;
  90. }
  91. HRESULT C_dxj_DDEnumObject::getItem( long index, DxDriverInfo *info)
  92. {
  93. if (m_pList==NULL) return E_FAIL;
  94. if (index < 0) return E_INVALIDARG;
  95. if (index >= m_nCount) return E_INVALIDARG;
  96. memcpy(info,&(m_pList[index]),sizeof(DxDriverInfo));
  97. return S_OK;
  98. }
  99. HRESULT C_dxj_DDEnumObject::getCount(long *retVal)
  100. {
  101. *retVal=m_nCount;
  102. return S_OK;
  103. }