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.

181 lines
3.9 KiB

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