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.

244 lines
6.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumconnectionsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DPEnumConnectionsObj.h"
  14. #include "DPAddressObj.h"
  15. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  16. extern HRESULT DPLBSTRtoPPGUID(LPGUID *,BSTR);
  17. /////////////////////////////////////////////////////////////////////////////
  18. /////////////////////////////////////////////////////////////////////////////
  19. extern "C" BOOL FAR PASCAL myEnumConnectionsCallback(
  20. LPCGUID lpguidSP,
  21. LPVOID lpConnection,
  22. DWORD dwConnectionSize,
  23. LPCDPNAME lpName,
  24. DWORD dwFlags,
  25. LPVOID lpArg
  26. ){
  27. DPF(1,"Entered objEnumConnectionsCallback\r\n");
  28. C_dxj_DPEnumConnectionsObject *pObj=(C_dxj_DPEnumConnectionsObject*)lpArg;
  29. if (pObj==NULL) return TRUE;
  30. if (pObj->m_nCount >= pObj->m_nMax)
  31. {
  32. pObj->m_nMax += 10;
  33. if (pObj->m_pList)
  34. pObj->m_pList=(DPConnection*)realloc(pObj->m_pList,sizeof(DPConnection)* pObj->m_nMax);
  35. else
  36. pObj->m_pList=(DPConnection*)malloc(sizeof(DPConnection)* pObj->m_nMax);
  37. if (pObj->m_pList==NULL)
  38. {
  39. pObj->m_bProblem=TRUE;
  40. return FALSE;
  41. }
  42. if (pObj->m_pList2)
  43. pObj->m_pList2=(I_dxj_DPAddress**)realloc(pObj->m_pList,sizeof(void*) * pObj->m_nMax);
  44. else
  45. pObj->m_pList2=(I_dxj_DPAddress**)malloc(sizeof(void*) * pObj->m_nMax);
  46. if (pObj->m_pList2==NULL)
  47. {
  48. pObj->m_bProblem=TRUE;
  49. return FALSE;
  50. }
  51. }
  52. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPConnection));
  53. pObj->m_pList2[pObj->m_nCount]=NULL;
  54. I_dxj_DPAddress *address=NULL;
  55. if (lpName->lpszShortName)
  56. pObj->m_pList[pObj->m_nCount].strShortName = SysAllocString(lpName->lpszShortName);
  57. if (lpName->lpszLongName)
  58. pObj->m_pList[pObj->m_nCount].strLongName = SysAllocString(lpName->lpszLongName);
  59. if (lpguidSP)
  60. pObj->m_pList[pObj->m_nCount].strGuid = DPLGUIDtoBSTR((LPGUID)lpguidSP);
  61. pObj->m_pList[pObj->m_nCount].lFlags=(DWORD)dwFlags;
  62. //internal create does the addref.
  63. #pragma message ("make sure InternalCreate does addref")
  64. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&address));
  65. pObj->m_pList2[pObj->m_nCount]=address;
  66. if (address) address->setAddress((long)PtrToLong(lpConnection),(long)dwConnectionSize); //bugbug SUNDOWN
  67. pObj->m_nCount++;
  68. return TRUE;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. C_dxj_DPEnumConnectionsObject::C_dxj_DPEnumConnectionsObject()
  72. {
  73. m_nMax=0;
  74. m_pList=NULL;
  75. m_pList2=NULL;
  76. m_nCount=0;
  77. m_bProblem=FALSE;
  78. }
  79. C_dxj_DPEnumConnectionsObject::~C_dxj_DPEnumConnectionsObject()
  80. {
  81. //empty list
  82. if (m_pList){
  83. for (int i=0;i<m_nCount;i++)
  84. {
  85. DPConnection *conn=&(m_pList[i]);
  86. if (conn->strShortName ) SysFreeString(conn->strShortName);
  87. if (conn->strLongName) SysFreeString(conn->strLongName);
  88. if (conn->strGuid) SysFreeString(conn->strGuid);
  89. }
  90. free(m_pList);
  91. }
  92. if (m_pList2){
  93. for (int i=0;i<m_nCount;i++)
  94. {
  95. if (m_pList2[i]) m_pList2[i]->Release();
  96. }
  97. free(m_pList2);
  98. }
  99. }
  100. HRESULT C_dxj_DPEnumConnectionsObject::create(
  101. IDirectPlay3 * pdp,
  102. BSTR strGuid,
  103. long flags, I_dxj_DPEnumConnections **ppRet)
  104. {
  105. HRESULT hr;
  106. C_dxj_DPEnumConnectionsObject *pNew=NULL;
  107. GUID g;
  108. LPGUID pguid=&g;
  109. hr=DPLBSTRtoPPGUID(&pguid,strGuid);
  110. if FAILED(hr) return hr;
  111. *ppRet=NULL;
  112. pNew= new CComObject<C_dxj_DPEnumConnectionsObject>;
  113. if (!pNew) return E_OUTOFMEMORY;
  114. pNew->m_bProblem=FALSE;
  115. hr = pdp->EnumConnections(pguid,
  116. myEnumConnectionsCallback,
  117. pNew, (long)flags);
  118. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  119. #pragma message ("make sure free on failure cleans up in enumerators on STrings and objects")
  120. if FAILED(hr)
  121. {
  122. //free(pNew->m_pList);
  123. //pNew->m_pList=NULL;
  124. //destructor will clean up properly
  125. delete pNew;
  126. return hr;
  127. }
  128. hr=pNew->QueryInterface(IID_I_dxj_DPEnumConnections,(void**)ppRet);
  129. return hr;
  130. }
  131. /* DEAD CODE
  132. HRESULT C_dxj_DPEnumConnectionsObject::getItem( long index, DPConnection *info)
  133. {
  134. if (m_pList==NULL) return E_FAIL;
  135. if (index < 0) return E_INVALIDARG;
  136. if (index >= m_nCount) return E_INVALIDARG;
  137. if (!info) return E_INVALIDARG;
  138. if (info->strGuid) SysFreeString(info->strGuid);
  139. if (info->strShortName) SysFreeString(info->strShortName);
  140. if (info->strLongName) SysFreeString(info->strLongName);
  141. info->strGuid=SysAllocString(m_pList[index].strGuid);
  142. info->strShortName=SysAllocString(m_pList[index].strShortName);
  143. info->strLongName=SysAllocString(m_pList[index].strLongName);
  144. info->lFlags=m_pList[index].lFlags;
  145. return S_OK;
  146. }
  147. */
  148. HRESULT C_dxj_DPEnumConnectionsObject::getFlags( long index, long *retV)
  149. {
  150. if (m_pList==NULL) return E_FAIL;
  151. if (index < 1) return E_INVALIDARG;
  152. if (index > m_nCount) return E_INVALIDARG;
  153. *retV=m_pList[index-1].lFlags;
  154. return S_OK;
  155. }
  156. HRESULT C_dxj_DPEnumConnectionsObject::getGuid( long index, BSTR *retV)
  157. {
  158. if (m_pList==NULL) return E_FAIL;
  159. if (index < 1) return E_INVALIDARG;
  160. if (index > m_nCount) return E_INVALIDARG;
  161. *retV=SysAllocString(m_pList[index-1].strGuid);
  162. return S_OK;
  163. }
  164. HRESULT C_dxj_DPEnumConnectionsObject::getName( long index, BSTR *retV)
  165. {
  166. if (m_pList==NULL) return E_FAIL;
  167. if (index < 1) return E_INVALIDARG;
  168. if (index > m_nCount) return E_INVALIDARG;
  169. *retV=SysAllocString(m_pList[index-1].strShortName);
  170. return S_OK;
  171. }
  172. /*
  173. HRESULT C_dxj_DPEnumConnectionsObject::getLongName( long index, BSTR *retV)
  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. *retV=SysAllocString(m_pList[index-1].strLongName);
  179. return S_OK;
  180. }
  181. */
  182. HRESULT C_dxj_DPEnumConnectionsObject::getAddress(long index,I_dxj_DPAddress **ppret){
  183. if (m_pList2==NULL) return E_FAIL;
  184. if (index < 1) return E_INVALIDARG;
  185. if (index > m_nCount) return E_INVALIDARG;
  186. if (m_pList2[index-1]==NULL) return E_FAIL;
  187. HRESULT hr=m_pList2[index-1]->QueryInterface(IID_I_dxj_DPAddress,(void**)ppret);
  188. return hr;
  189. }
  190. HRESULT C_dxj_DPEnumConnectionsObject::getCount(long *retVal)
  191. {
  192. *retVal=m_nCount;
  193. return S_OK;
  194. }