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.

133 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddenumexobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxglobobj.h"
  14. #include "DDEnumExObj.h"
  15. extern "C" BSTR GUIDtoBSTR(LPGUID pGuid);
  16. extern "C" BOOL PASCAL objDirectDrawEnumExCallback(
  17. GUID FAR *lpGUID,
  18. LPSTR lpDriverDescription,
  19. LPSTR lpDriverName,
  20. LPVOID lpArg,
  21. HANDLE hMon
  22. )
  23. {
  24. DPF(1,"Entered objDirectDrawEnumExCallback \r\n");
  25. C_dxj_DDEnumExObject *pObj=(C_dxj_DDEnumExObject*)lpArg;
  26. if (pObj==NULL) return DDENUMRET_OK;
  27. if (pObj->m_nCount >= pObj->m_nMax)
  28. {
  29. pObj->m_nMax += 10;
  30. pObj->m_pList=(DriverInfoEx*)realloc(pObj->m_pList,sizeof(DriverInfoEx)* pObj->m_nMax);
  31. if (pObj->m_pList==NULL)
  32. {
  33. pObj->m_bProblem=TRUE;
  34. return FALSE;
  35. }
  36. }
  37. USES_CONVERSION;
  38. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DriverInfoEx));
  39. pObj->m_pList[pObj->m_nCount].guid=GUIDtoBSTR((GUID*)lpGUID);
  40. if (lpDriverDescription!=NULL) {
  41. pObj->m_pList[pObj->m_nCount].description=T2BSTR(lpDriverDescription);
  42. }
  43. if (lpDriverName!=NULL){
  44. pObj->m_pList[pObj->m_nCount].name=T2BSTR(lpDriverName);
  45. }
  46. pObj->m_pList[pObj->m_nCount].hMon=hMon
  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].guid);
  64. if (m_pList[i].description) SysFreeString(m_pList[i].description);
  65. if (m_pList[i].name) SysFreeString(m_pList[i].name);
  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, DriverInfo *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(DriverInfo));
  97. return S_OK;
  98. }
  99. HRESULT C_dxj_DDEnumObject::getCount(long *retVal)
  100. {
  101. *retVal=m_nCount;
  102. return S_OK;
  103. }