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.

188 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxglob7obj.h"
  14. #include "DPEnumObj.h"
  15. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  16. //typedef HRESULT (__stdcall *DIRECTPLAYENUMERATE)( LPDPENUMDPCALLBACK, LPVOID );
  17. extern "C" BOOL PASCAL objEnumServiceProvidersCallback(LPGUID lpGUID, LPWSTR lpName,
  18. DWORD dwMajorVersion,DWORD dwMinorVersion, void *lpArg)
  19. {
  20. DPF(1,"Entered objEnumServiceProvidersCallback\r\n");
  21. C_dxj_DPEnumObject *pObj=(C_dxj_DPEnumObject*)lpArg;
  22. if (pObj==NULL) return FALSE;
  23. if (pObj->m_nCount >= pObj->m_nMax)
  24. {
  25. pObj->m_nMax += 10;
  26. if (pObj->m_pList)
  27. pObj->m_pList=(DPServiceProvider*)realloc(pObj->m_pList,sizeof(DPServiceProvider)* pObj->m_nMax);
  28. else
  29. pObj->m_pList=(DPServiceProvider*)malloc(sizeof(DPServiceProvider)* pObj->m_nMax);
  30. if (pObj->m_pList==NULL)
  31. {
  32. pObj->m_bProblem=TRUE;
  33. return FALSE;
  34. }
  35. }
  36. USES_CONVERSION;
  37. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPServiceProvider));
  38. pObj->m_pList[pObj->m_nCount].strGuid=DPLGUIDtoBSTR((GUID*)lpGUID);
  39. if (lpName!=NULL){
  40. pObj->m_pList[pObj->m_nCount].strName=W2BSTR(lpName);
  41. }
  42. pObj->m_pList[pObj->m_nCount].lMajorVersion=(DWORD)dwMajorVersion;
  43. pObj->m_pList[pObj->m_nCount].lMinorVersion=(DWORD)dwMinorVersion;
  44. pObj->m_nCount++;
  45. return TRUE;
  46. }
  47. C_dxj_DPEnumObject::C_dxj_DPEnumObject()
  48. {
  49. m_nMax=0;
  50. m_pList=NULL;
  51. m_nCount=0;
  52. m_bProblem=FALSE;
  53. }
  54. C_dxj_DPEnumObject::~C_dxj_DPEnumObject()
  55. {
  56. //empty list
  57. if (m_pList){
  58. for (int i=0;i<m_nCount;i++)
  59. {
  60. if (m_pList[i].strGuid) SysFreeString(m_pList[i].strGuid);
  61. if (m_pList[i].strName) SysFreeString(m_pList[i].strName);
  62. }
  63. free(m_pList);
  64. }
  65. }
  66. HRESULT C_dxj_DPEnumObject::create(DIRECTPLAYENUMERATE pcbFunc,I_dxj_DPEnumServiceProviders **ppRet)
  67. {
  68. HRESULT hr;
  69. C_dxj_DPEnumObject *pNew=NULL;
  70. //ASSERT(ppRet,"C_dxj_DPEnumObject::create passed invalid arg");
  71. *ppRet=NULL;
  72. pNew= new CComObject<C_dxj_DPEnumObject>;
  73. if (!pNew) return E_OUTOFMEMORY;
  74. pNew->m_bProblem=FALSE;
  75. hr=pcbFunc(objEnumServiceProvidersCallback,(void*)pNew);
  76. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  77. if FAILED(hr)
  78. {
  79. free(pNew->m_pList);
  80. pNew->m_pList=NULL;
  81. delete pNew;
  82. return hr;
  83. }
  84. hr=pNew->QueryInterface(IID_I_dxj_DPEnumServiceProviders,(void**)ppRet);
  85. return hr;
  86. }
  87. HRESULT C_dxj_DPEnumObject::getName( long index, BSTR __RPC_FAR *ret)
  88. {
  89. if (m_pList==NULL) return E_FAIL;
  90. if (index < 1) return E_INVALIDARG;
  91. if (index > m_nCount) return E_INVALIDARG;
  92. *ret=SysAllocString(m_pList[index-1].strName);
  93. return S_OK;
  94. }
  95. HRESULT C_dxj_DPEnumObject::getGuid( long index, BSTR __RPC_FAR *ret)
  96. {
  97. if (m_pList==NULL) return E_FAIL;
  98. if (index < 1) return E_INVALIDARG;
  99. if (index > m_nCount) return E_INVALIDARG;
  100. *ret=SysAllocString(m_pList[index-1].strGuid);
  101. return S_OK;
  102. }
  103. HRESULT C_dxj_DPEnumObject::getVersion(
  104. /* [in] */ long index,
  105. /* [in] */ long __RPC_FAR *majorVersion,
  106. /* [out][in] */ long __RPC_FAR *minorVersion)
  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. *majorVersion=m_pList[index-1].lMajorVersion;
  112. *minorVersion=m_pList[index-1].lMinorVersion;
  113. return S_OK;
  114. }
  115. HRESULT C_dxj_DPEnumObject::getCount(long *retVal)
  116. {
  117. *retVal=m_nCount;
  118. return S_OK;
  119. }
  120. /*
  121. HRESULT C_dxj_DPEnumObject::getItem( long index, DPServiceProvider *info)
  122. {
  123. if (m_pList==NULL) return E_FAIL;
  124. if (index < 0) return E_INVALIDARG;
  125. if (index >= m_nCount) return E_INVALIDARG;
  126. if (!info) return E_INVALIDARG;
  127. ZeroMemory(info,sizeof(DPServiceProvider));
  128. if (info->strGuid) SysFreeString(info->strGuid);
  129. if (info->strName) SysFreeString(info->strName);
  130. if (m_pList[index].strGuid) info->strGuid=SysAllocString(m_pList[index].strGuid);
  131. if (m_pList[index].strName) info->strName=SysAllocString(m_pList[index].strName);
  132. info->lMajorVersion=m_pList[index].lMajorVersion;
  133. info->lMinorVersion=m_pList[index].lMinorVersion;
  134. return S_OK;
  135. }
  136. */