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.

239 lines
5.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumplayersobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DPEnumPlayersObj.h"
  14. extern BSTR GUIDtoBSTR(LPGUID pGuid);
  15. extern HRESULT BSTRtoPPGUID(LPGUID *,BSTR);
  16. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  17. extern HRESULT DPLBSTRtoPPGUID(LPGUID *,BSTR);
  18. /////////////////////////////////////////////////////////////////////////////
  19. // The callback is invoked as a result of IDirectPlay2::EnumPlayers(),
  20. // IDirectPlay2::EnumGroups() and IDirectPlay2::EnumGroupPlayers() calls.
  21. /////////////////////////////////////////////////////////////////////////////
  22. extern "C" BOOL PASCAL objEnumPlayersCallback2(DPID dpid,
  23. DWORD dwPlayerType, LPCDPNAME lpName,
  24. DWORD dwFlags, LPVOID lpArg)
  25. {
  26. DPF(1,"Entered objEnumPlayersCallback2 \r\n");
  27. C_dxj_DPEnumPlayersObject *pObj=(C_dxj_DPEnumPlayersObject*)lpArg;
  28. if (pObj==NULL) return TRUE;
  29. if (pObj->m_nCount >= pObj->m_nMax)
  30. {
  31. pObj->m_nMax += 10;
  32. if (pObj->m_pList)
  33. pObj->m_pList=(DPPlayerInfo*)realloc(pObj->m_pList,sizeof(DPPlayerInfo)* pObj->m_nMax);
  34. else
  35. pObj->m_pList=(DPPlayerInfo*)malloc(sizeof(DPPlayerInfo)* 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(DPPlayerInfo));
  44. pObj->m_pList[pObj->m_nCount].lDPID=(long)dpid;
  45. pObj->m_pList[pObj->m_nCount].lPlayerType=(long)dwPlayerType;
  46. pObj->m_pList[pObj->m_nCount].lFlags=(long)dwFlags;
  47. //unsing unicode DPLAY
  48. pObj->m_pList[pObj->m_nCount].strShortName=SysAllocString(lpName->lpszShortName);
  49. pObj->m_pList[pObj->m_nCount].strLongName=SysAllocString(lpName->lpszLongName);
  50. pObj->m_nCount++;
  51. return TRUE;
  52. }
  53. C_dxj_DPEnumPlayersObject::C_dxj_DPEnumPlayersObject()
  54. {
  55. m_nMax=0;
  56. m_pList=NULL;
  57. m_nCount=0;
  58. m_bProblem=FALSE;
  59. }
  60. C_dxj_DPEnumPlayersObject::~C_dxj_DPEnumPlayersObject()
  61. {
  62. //empty list
  63. if (m_pList){
  64. for (int i=0;i<m_nCount;i++)
  65. {
  66. if( m_pList[i].strShortName) SysFreeString(m_pList[i].strShortName);
  67. if( m_pList[i].strLongName) SysFreeString(m_pList[i].strLongName);
  68. }
  69. free(m_pList);
  70. }
  71. }
  72. HRESULT C_dxj_DPEnumPlayersObject::create(IDirectPlay3 * pdp, long customFlags,long id, BSTR strGuid,long flags, I_dxj_DPEnumPlayers2 **ppRet)
  73. {
  74. HRESULT hr;
  75. C_dxj_DPEnumPlayersObject *pNew=NULL;
  76. GUID g;
  77. LPGUID pguid=&g;
  78. hr= DPLBSTRtoPPGUID(&pguid,strGuid);
  79. if FAILED(hr) return hr;
  80. *ppRet=NULL;
  81. pNew= new CComObject<C_dxj_DPEnumPlayersObject>;
  82. if (!pNew) return E_OUTOFMEMORY;
  83. pNew->m_bProblem=FALSE;
  84. switch (customFlags){
  85. case DPENUMGROUPSINGROUP:
  86. hr = pdp->EnumGroupsInGroup((DPID)id,(GUID*) pguid,
  87. objEnumPlayersCallback2,
  88. pNew, (long)flags);
  89. break;
  90. case DPENUMPLAYERS:
  91. hr=pdp->EnumPlayers((GUID*) pguid,
  92. objEnumPlayersCallback2,
  93. pNew, (long)flags);
  94. break;
  95. case DPENUMGROUPPLAYERS:
  96. hr = pdp->EnumGroupPlayers( (DPID)id, (GUID*)pguid,
  97. objEnumPlayersCallback2,
  98. pNew, flags);
  99. break;
  100. case DPENUMGROUPS:
  101. hr=pdp->EnumGroups( (GUID*)pguid,
  102. objEnumPlayersCallback2,
  103. pNew, (DWORD)flags);
  104. break;
  105. default:
  106. hr=E_INVALIDARG;
  107. break;
  108. }
  109. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  110. if FAILED(hr)
  111. {
  112. free(pNew->m_pList);
  113. pNew->m_pList=NULL;
  114. delete pNew;
  115. return hr;
  116. }
  117. hr=pNew->QueryInterface(IID_I_dxj_DPEnumPlayers2,(void**)ppRet);
  118. return hr;
  119. }
  120. /* DEAD
  121. HRESULT C_dxj_DPEnumPlayersObject::getItem( long index, DPPlayerInfo *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. memcpy(info,&(m_pList[index]),sizeof(DPPlayerInfo));
  127. if (info->strShortName) SysFreeString(info->strShortName);
  128. if (info->strLongName) SysFreeString(info->strLongName);
  129. //unsing unicode DPLAY
  130. info->strShortName=SysAllocString(m_pList[index].strShortName);
  131. info->strLongName=SysAllocString(m_pList[index].strLongName);
  132. return S_OK;
  133. }
  134. */
  135. HRESULT C_dxj_DPEnumPlayersObject::getFlags(
  136. /* [in] */ long index,
  137. /* [retval][out] */ long __RPC_FAR *ret)
  138. {
  139. if (m_pList==NULL) return E_FAIL;
  140. if (index < 1) return E_INVALIDARG;
  141. if (index > m_nCount) return E_INVALIDARG;
  142. *ret=m_pList[index-1].lFlags;
  143. return S_OK;
  144. }
  145. HRESULT C_dxj_DPEnumPlayersObject::getType(
  146. /* [in] */ long index,
  147. /* [retval][out] */ long __RPC_FAR *ret)
  148. {
  149. if (m_pList==NULL) return E_FAIL;
  150. if (index < 1) return E_INVALIDARG;
  151. if (index > m_nCount) return E_INVALIDARG;
  152. *ret=m_pList[index-1].lPlayerType;
  153. return S_OK;
  154. }
  155. HRESULT C_dxj_DPEnumPlayersObject::getDPID(
  156. /* [in] */ long index,
  157. /* [retval][out] */ long __RPC_FAR *ret)
  158. {
  159. if (m_pList==NULL) return E_FAIL;
  160. if (index < 1) return E_INVALIDARG;
  161. if (index > m_nCount) return E_INVALIDARG;
  162. *ret=m_pList[index-1].lDPID;
  163. return S_OK;
  164. }
  165. HRESULT C_dxj_DPEnumPlayersObject::getShortName(
  166. /* [in] */ long index,
  167. /* [retval][out] */ BSTR __RPC_FAR *ret)
  168. {
  169. if (m_pList==NULL) return E_FAIL;
  170. if (index < 1) return E_INVALIDARG;
  171. if (index > m_nCount) return E_INVALIDARG;
  172. *ret=SysAllocString(m_pList[index-1].strShortName);
  173. return S_OK;
  174. }
  175. HRESULT C_dxj_DPEnumPlayersObject::getLongName(
  176. /* [in] */ long index,
  177. /* [retval][out] */ BSTR __RPC_FAR *ret)
  178. {
  179. if (m_pList==NULL) return E_FAIL;
  180. if (index < 1) return E_INVALIDARG;
  181. if (index > m_nCount) return E_INVALIDARG;
  182. *ret=SysAllocString(m_pList[index-1].strLongName);
  183. return S_OK;
  184. }
  185. HRESULT C_dxj_DPEnumPlayersObject::getCount(long *retVal)
  186. {
  187. *retVal=m_nCount;
  188. return S_OK;
  189. }