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.

245 lines
6.1 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. {
  34. void* tmp = realloc(pObj->m_pList,sizeof(DPPlayerInfo)* pObj->m_nMax);
  35. if (tmp)
  36. pObj->m_pList=(DPPlayerInfo*)tmp;
  37. else
  38. return FALSE;
  39. }
  40. else
  41. pObj->m_pList=(DPPlayerInfo*)malloc(sizeof(DPPlayerInfo)* pObj->m_nMax);
  42. if (pObj->m_pList==NULL)
  43. {
  44. pObj->m_bProblem=TRUE;
  45. return FALSE;
  46. }
  47. }
  48. USES_CONVERSION;
  49. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPPlayerInfo));
  50. pObj->m_pList[pObj->m_nCount].lDPID=(long)dpid;
  51. pObj->m_pList[pObj->m_nCount].lPlayerType=(long)dwPlayerType;
  52. pObj->m_pList[pObj->m_nCount].lFlags=(long)dwFlags;
  53. //unsing unicode DPLAY
  54. pObj->m_pList[pObj->m_nCount].strShortName=SysAllocString(lpName->lpszShortName);
  55. pObj->m_pList[pObj->m_nCount].strLongName=SysAllocString(lpName->lpszLongName);
  56. pObj->m_nCount++;
  57. return TRUE;
  58. }
  59. C_dxj_DPEnumPlayersObject::C_dxj_DPEnumPlayersObject()
  60. {
  61. m_nMax=0;
  62. m_pList=NULL;
  63. m_nCount=0;
  64. m_bProblem=FALSE;
  65. }
  66. C_dxj_DPEnumPlayersObject::~C_dxj_DPEnumPlayersObject()
  67. {
  68. //empty list
  69. if (m_pList){
  70. for (int i=0;i<m_nCount;i++)
  71. {
  72. if( m_pList[i].strShortName) SysFreeString((BSTR)m_pList[i].strShortName);
  73. if( m_pList[i].strLongName) SysFreeString((BSTR)m_pList[i].strLongName);
  74. }
  75. free(m_pList);
  76. }
  77. }
  78. HRESULT C_dxj_DPEnumPlayersObject::create(IDirectPlay3 * pdp, long customFlags,long id, BSTR strGuid,long flags, I_dxj_DPEnumPlayers2 **ppRet)
  79. {
  80. HRESULT hr;
  81. C_dxj_DPEnumPlayersObject *pNew=NULL;
  82. GUID g;
  83. LPGUID pguid=&g;
  84. hr= DPLBSTRtoPPGUID(&pguid,strGuid);
  85. if FAILED(hr) return hr;
  86. *ppRet=NULL;
  87. pNew= new CComObject<C_dxj_DPEnumPlayersObject>;
  88. if (!pNew) return E_OUTOFMEMORY;
  89. pNew->m_bProblem=FALSE;
  90. switch (customFlags){
  91. case DPENUMGROUPSINGROUP:
  92. hr = pdp->EnumGroupsInGroup((DPID)id,(GUID*) pguid,
  93. objEnumPlayersCallback2,
  94. pNew, (long)flags);
  95. break;
  96. case DPENUMPLAYERS:
  97. hr=pdp->EnumPlayers((GUID*) pguid,
  98. objEnumPlayersCallback2,
  99. pNew, (long)flags);
  100. break;
  101. case DPENUMGROUPPLAYERS:
  102. hr = pdp->EnumGroupPlayers( (DPID)id, (GUID*)pguid,
  103. objEnumPlayersCallback2,
  104. pNew, flags);
  105. break;
  106. case DPENUMGROUPS:
  107. hr=pdp->EnumGroups( (GUID*)pguid,
  108. objEnumPlayersCallback2,
  109. pNew, (DWORD)flags);
  110. break;
  111. default:
  112. hr=E_INVALIDARG;
  113. break;
  114. }
  115. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  116. if FAILED(hr)
  117. {
  118. free(pNew->m_pList);
  119. pNew->m_pList=NULL;
  120. delete pNew;
  121. return hr;
  122. }
  123. hr=pNew->QueryInterface(IID_I_dxj_DPEnumPlayers2,(void**)ppRet);
  124. return hr;
  125. }
  126. /* DEAD
  127. HRESULT C_dxj_DPEnumPlayersObject::getItem( long index, DPPlayerInfo *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. memcpy(info,&(m_pList[index]),sizeof(DPPlayerInfo));
  133. if (info->strShortName) SysFreeString((BSTR)info->strShortName);
  134. if (info->strLongName) SysFreeString((BSTR)info->strLongName);
  135. //unsing unicode DPLAY
  136. info->strShortName=SysAllocString(m_pList[index].strShortName);
  137. info->strLongName=SysAllocString(m_pList[index].strLongName);
  138. return S_OK;
  139. }
  140. */
  141. HRESULT C_dxj_DPEnumPlayersObject::getFlags(
  142. /* [in] */ long index,
  143. /* [retval][out] */ long __RPC_FAR *ret)
  144. {
  145. if (m_pList==NULL) return E_FAIL;
  146. if (index < 1) return E_INVALIDARG;
  147. if (index > m_nCount) return E_INVALIDARG;
  148. *ret=m_pList[index-1].lFlags;
  149. return S_OK;
  150. }
  151. HRESULT C_dxj_DPEnumPlayersObject::getType(
  152. /* [in] */ long index,
  153. /* [retval][out] */ long __RPC_FAR *ret)
  154. {
  155. if (m_pList==NULL) return E_FAIL;
  156. if (index < 1) return E_INVALIDARG;
  157. if (index > m_nCount) return E_INVALIDARG;
  158. *ret=m_pList[index-1].lPlayerType;
  159. return S_OK;
  160. }
  161. HRESULT C_dxj_DPEnumPlayersObject::getDPID(
  162. /* [in] */ long index,
  163. /* [retval][out] */ long __RPC_FAR *ret)
  164. {
  165. if (m_pList==NULL) return E_FAIL;
  166. if (index < 1) return E_INVALIDARG;
  167. if (index > m_nCount) return E_INVALIDARG;
  168. *ret=m_pList[index-1].lDPID;
  169. return S_OK;
  170. }
  171. HRESULT C_dxj_DPEnumPlayersObject::getShortName(
  172. /* [in] */ long index,
  173. /* [retval][out] */ BSTR __RPC_FAR *ret)
  174. {
  175. if (m_pList==NULL) return E_FAIL;
  176. if (index < 1) return E_INVALIDARG;
  177. if (index > m_nCount) return E_INVALIDARG;
  178. *ret=SysAllocString(m_pList[index-1].strShortName);
  179. return S_OK;
  180. }
  181. HRESULT C_dxj_DPEnumPlayersObject::getLongName(
  182. /* [in] */ long index,
  183. /* [retval][out] */ BSTR __RPC_FAR *ret)
  184. {
  185. if (m_pList==NULL) return E_FAIL;
  186. if (index < 1) return E_INVALIDARG;
  187. if (index > m_nCount) return E_INVALIDARG;
  188. *ret=SysAllocString(m_pList[index-1].strLongName);
  189. return S_OK;
  190. }
  191. HRESULT C_dxj_DPEnumPlayersObject::getCount(long *retVal)
  192. {
  193. *retVal=m_nCount;
  194. return S_OK;
  195. }