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.

194 lines
4.5 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. {
  28. void* tmp = realloc(pObj->m_pList,sizeof(DPServiceProvider)* pObj->m_nMax);
  29. if (tmp)
  30. pObj->m_pList=(DPServiceProvider*)tmp;
  31. else
  32. return FALSE;
  33. }
  34. else
  35. pObj->m_pList=(DPServiceProvider*)malloc(sizeof(DPServiceProvider)* pObj->m_nMax);
  36. if (pObj->m_pList==NULL)
  37. {
  38. pObj->m_bProblem=TRUE;
  39. return FALSE;
  40. }
  41. }
  42. USES_CONVERSION;
  43. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPServiceProvider));
  44. pObj->m_pList[pObj->m_nCount].strGuid=DPLGUIDtoBSTR((GUID*)lpGUID);
  45. if (lpName!=NULL){
  46. pObj->m_pList[pObj->m_nCount].strName=W2BSTR(lpName);
  47. }
  48. pObj->m_pList[pObj->m_nCount].lMajorVersion=(DWORD)dwMajorVersion;
  49. pObj->m_pList[pObj->m_nCount].lMinorVersion=(DWORD)dwMinorVersion;
  50. pObj->m_nCount++;
  51. return TRUE;
  52. }
  53. C_dxj_DPEnumObject::C_dxj_DPEnumObject()
  54. {
  55. m_nMax=0;
  56. m_pList=NULL;
  57. m_nCount=0;
  58. m_bProblem=FALSE;
  59. }
  60. C_dxj_DPEnumObject::~C_dxj_DPEnumObject()
  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((BSTR)m_pList[i].strGuid);
  67. if (m_pList[i].strName) SysFreeString((BSTR)m_pList[i].strName);
  68. }
  69. free(m_pList);
  70. }
  71. }
  72. HRESULT C_dxj_DPEnumObject::create(DIRECTPLAYENUMERATE pcbFunc,I_dxj_DPEnumServiceProviders **ppRet)
  73. {
  74. HRESULT hr;
  75. C_dxj_DPEnumObject *pNew=NULL;
  76. //ASSERT(ppRet,"C_dxj_DPEnumObject::create passed invalid arg");
  77. *ppRet=NULL;
  78. pNew= new CComObject<C_dxj_DPEnumObject>;
  79. if (!pNew) return E_OUTOFMEMORY;
  80. pNew->m_bProblem=FALSE;
  81. hr=pcbFunc(objEnumServiceProvidersCallback,(void*)pNew);
  82. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  83. if FAILED(hr)
  84. {
  85. free(pNew->m_pList);
  86. pNew->m_pList=NULL;
  87. delete pNew;
  88. return hr;
  89. }
  90. hr=pNew->QueryInterface(IID_I_dxj_DPEnumServiceProviders,(void**)ppRet);
  91. return hr;
  92. }
  93. HRESULT C_dxj_DPEnumObject::getName( long index, BSTR __RPC_FAR *ret)
  94. {
  95. if (m_pList==NULL) return E_FAIL;
  96. if (index < 1) return E_INVALIDARG;
  97. if (index > m_nCount) return E_INVALIDARG;
  98. *ret=SysAllocString(m_pList[index-1].strName);
  99. return S_OK;
  100. }
  101. HRESULT C_dxj_DPEnumObject::getGuid( long index, BSTR __RPC_FAR *ret)
  102. {
  103. if (m_pList==NULL) return E_FAIL;
  104. if (index < 1) return E_INVALIDARG;
  105. if (index > m_nCount) return E_INVALIDARG;
  106. *ret=SysAllocString(m_pList[index-1].strGuid);
  107. return S_OK;
  108. }
  109. HRESULT C_dxj_DPEnumObject::getVersion(
  110. /* [in] */ long index,
  111. /* [in] */ long __RPC_FAR *majorVersion,
  112. /* [out][in] */ long __RPC_FAR *minorVersion)
  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. *majorVersion=m_pList[index-1].lMajorVersion;
  118. *minorVersion=m_pList[index-1].lMinorVersion;
  119. return S_OK;
  120. }
  121. HRESULT C_dxj_DPEnumObject::getCount(long *retVal)
  122. {
  123. *retVal=m_nCount;
  124. return S_OK;
  125. }
  126. /*
  127. HRESULT C_dxj_DPEnumObject::getItem( long index, DPServiceProvider *info)
  128. {
  129. if (m_pList==NULL) return E_FAIL;
  130. if (index < 0) return E_INVALIDARG;
  131. if (index >= m_nCount) return E_INVALIDARG;
  132. if (!info) return E_INVALIDARG;
  133. ZeroMemory(info,sizeof(DPServiceProvider));
  134. if (info->strGuid) SysFreeString((BSTR)info->strGuid);
  135. if (info->strName) SysFreeString((BSTR)info->strName);
  136. if (m_pList[index].strGuid) info->strGuid=SysAllocString(m_pList[index].strGuid);
  137. if (m_pList[index].strName) info->strName=SysAllocString(m_pList[index].strName);
  138. info->lMajorVersion=m_pList[index].lMajorVersion;
  139. info->lMinorVersion=m_pList[index].lMinorVersion;
  140. return S_OK;
  141. }
  142. */