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.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddenum.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxGlob7Obj.h"
  14. #include "DDEnumObj.h"
  15. extern 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. DPF(1,"Entered objDirectDrawEnumCallback \r\n");
  24. C_dxj_DDEnumObject *pObj=(C_dxj_DDEnumObject*)lpArg;
  25. if (pObj==NULL) return DDENUMRET_OK;
  26. if (pObj->m_nCount >= pObj->m_nMax)
  27. {
  28. pObj->m_nMax += 10;
  29. if (pObj->m_pList)
  30. pObj->m_pList=(DxDriverInfo*)realloc(pObj->m_pList,sizeof(DxDriverInfo)* pObj->m_nMax);
  31. else
  32. pObj->m_pList=(DxDriverInfo*)malloc(sizeof(DxDriverInfo)* pObj->m_nMax);
  33. if (pObj->m_pList==NULL)
  34. {
  35. pObj->m_bProblem=TRUE;
  36. return FALSE;
  37. }
  38. }
  39. USES_CONVERSION;
  40. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DxDriverInfo));
  41. pObj->m_pList[pObj->m_nCount].strGuid=GUIDtoBSTR((GUID*)lpGUID);
  42. if (lpDriverDescription!=NULL) {
  43. pObj->m_pList[pObj->m_nCount].strDescription=T2BSTR(lpDriverDescription);
  44. }
  45. if (lpDriverName!=NULL){
  46. pObj->m_pList[pObj->m_nCount].strName=T2BSTR(lpDriverName);
  47. }
  48. pObj->m_nCount++;
  49. return TRUE;
  50. }
  51. C_dxj_DDEnumObject::C_dxj_DDEnumObject()
  52. {
  53. m_nMax=0;
  54. m_pList=NULL;
  55. m_nCount=0;
  56. m_bProblem=FALSE;
  57. }
  58. C_dxj_DDEnumObject::~C_dxj_DDEnumObject()
  59. {
  60. //empty list
  61. if (m_pList){
  62. for (int i=0;i<m_nCount;i++)
  63. {
  64. if (m_pList[i].strGuid) SysFreeString(m_pList[i].strGuid);
  65. if (m_pList[i].strDescription) SysFreeString(m_pList[i].strDescription);
  66. if (m_pList[i].strName) SysFreeString(m_pList[i].strName);
  67. }
  68. free(m_pList);
  69. }
  70. }
  71. HRESULT C_dxj_DDEnumObject::create(DDENUMERATE pcbFunc,I_dxj_DDEnum **ppRet)
  72. {
  73. HRESULT hr;
  74. C_dxj_DDEnumObject *pNew=NULL;
  75. //ASSERT(ppRet,"C_dxj_DDEnumObject::create passed invalid arg");
  76. *ppRet=NULL;
  77. pNew= new CComObject<C_dxj_DDEnumObject>;
  78. if (!pNew) return E_OUTOFMEMORY;
  79. pNew->m_bProblem=FALSE;
  80. hr=pcbFunc(objDirectDrawEnumCallback,(void*)pNew);
  81. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  82. if FAILED(hr)
  83. {
  84. free(pNew->m_pList);
  85. pNew->m_pList=NULL;
  86. delete pNew;
  87. return hr;
  88. }
  89. hr=pNew->QueryInterface(IID_I_dxj_DDEnum,(void**)ppRet);
  90. return hr;
  91. }
  92. /*
  93. HRESULT C_dxj_DDEnumObject::getItem( long index, DxDriverInfo *inf)
  94. {
  95. if (m_pList==NULL) return E_FAIL;
  96. if (index < 0) return E_INVALIDARG;
  97. if (index >= m_nCount) return E_INVALIDARG;
  98. if (!inf) return E_FAIL;
  99. //C2819
  100. (*inf).strGuid=SysAllocString(m_pList[index].strGuid);
  101. (*inf).strDescription=SysAllocString(m_pList[index].strDescription);
  102. (*inf).strName=SysAllocString(m_pList[index].strName);
  103. return S_OK;
  104. }
  105. */
  106. HRESULT C_dxj_DDEnumObject::getGuid( long index, BSTR *info)
  107. {
  108. if (m_pList==NULL) return E_FAIL;
  109. if (index < 1) return E_INVALIDARG;
  110. if (index > m_nCount) return E_INVALIDARG;
  111. if (!info) return E_INVALIDARG;
  112. *info=SysAllocString(m_pList[index-1].strGuid);
  113. return S_OK;
  114. }
  115. HRESULT C_dxj_DDEnumObject::getName( long index, BSTR *info)
  116. {
  117. if (m_pList==NULL) return E_FAIL;
  118. if (index < 1) return E_INVALIDARG;
  119. if (index > m_nCount) return E_INVALIDARG;
  120. if (!info) return E_INVALIDARG;
  121. *info=SysAllocString(m_pList[index-1].strName);
  122. return S_OK;
  123. }
  124. HRESULT C_dxj_DDEnumObject::getDescription( long index, BSTR *info)
  125. {
  126. if (m_pList==NULL) return E_FAIL;
  127. if (index < 1) return E_INVALIDARG;
  128. if (index > m_nCount) return E_INVALIDARG;
  129. if (!info) return E_INVALIDARG;
  130. *info=SysAllocString(m_pList[index-1].strDescription);
  131. return S_OK;
  132. }
  133. HRESULT C_dxj_DDEnumObject::getCount(long *retVal)
  134. {
  135. *retVal=m_nCount;
  136. return S_OK;
  137. }