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.

250 lines
6.4 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. {
  35. void* tmp = realloc(pObj->m_pList,sizeof(DPConnection)* pObj->m_nMax);
  36. if (tmp)
  37. pObj->m_pList=(DPConnection*)tmp;
  38. else
  39. return FALSE;
  40. }
  41. else
  42. pObj->m_pList=(DPConnection*)malloc(sizeof(DPConnection)* pObj->m_nMax);
  43. if (pObj->m_pList==NULL)
  44. {
  45. pObj->m_bProblem=TRUE;
  46. return FALSE;
  47. }
  48. if (pObj->m_pList2)
  49. pObj->m_pList2=(I_dxj_DPAddress**)realloc(pObj->m_pList,sizeof(void*) * pObj->m_nMax);
  50. else
  51. pObj->m_pList2=(I_dxj_DPAddress**)malloc(sizeof(void*) * pObj->m_nMax);
  52. if (pObj->m_pList2==NULL)
  53. {
  54. pObj->m_bProblem=TRUE;
  55. return FALSE;
  56. }
  57. }
  58. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPConnection));
  59. pObj->m_pList2[pObj->m_nCount]=NULL;
  60. I_dxj_DPAddress *address=NULL;
  61. if (lpName->lpszShortName)
  62. pObj->m_pList[pObj->m_nCount].strShortName = SysAllocString(lpName->lpszShortName);
  63. if (lpName->lpszLongName)
  64. pObj->m_pList[pObj->m_nCount].strLongName = SysAllocString(lpName->lpszLongName);
  65. if (lpguidSP)
  66. pObj->m_pList[pObj->m_nCount].strGuid = DPLGUIDtoBSTR((LPGUID)lpguidSP);
  67. pObj->m_pList[pObj->m_nCount].lFlags=(DWORD)dwFlags;
  68. //internal create does the addref.
  69. #pragma message ("make sure InternalCreate does addref")
  70. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&address));
  71. pObj->m_pList2[pObj->m_nCount]=address;
  72. if (address) address->setAddress((long)PtrToLong(lpConnection),(long)dwConnectionSize); //bugbug SUNDOWN
  73. pObj->m_nCount++;
  74. return TRUE;
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. C_dxj_DPEnumConnectionsObject::C_dxj_DPEnumConnectionsObject()
  78. {
  79. m_nMax=0;
  80. m_pList=NULL;
  81. m_pList2=NULL;
  82. m_nCount=0;
  83. m_bProblem=FALSE;
  84. }
  85. C_dxj_DPEnumConnectionsObject::~C_dxj_DPEnumConnectionsObject()
  86. {
  87. //empty list
  88. if (m_pList){
  89. for (int i=0;i<m_nCount;i++)
  90. {
  91. DPConnection *conn=&(m_pList[i]);
  92. if (conn->strShortName ) SysFreeString((BSTR)conn->strShortName);
  93. if (conn->strLongName) SysFreeString((BSTR)conn->strLongName);
  94. if (conn->strGuid) SysFreeString((BSTR)conn->strGuid);
  95. }
  96. free(m_pList);
  97. }
  98. if (m_pList2){
  99. for (int i=0;i<m_nCount;i++)
  100. {
  101. if (m_pList2[i]) m_pList2[i]->Release();
  102. }
  103. free(m_pList2);
  104. }
  105. }
  106. HRESULT C_dxj_DPEnumConnectionsObject::create(
  107. IDirectPlay3 * pdp,
  108. BSTR strGuid,
  109. long flags, I_dxj_DPEnumConnections **ppRet)
  110. {
  111. HRESULT hr;
  112. C_dxj_DPEnumConnectionsObject *pNew=NULL;
  113. GUID g;
  114. LPGUID pguid=&g;
  115. hr=DPLBSTRtoPPGUID(&pguid,strGuid);
  116. if FAILED(hr) return hr;
  117. *ppRet=NULL;
  118. pNew= new CComObject<C_dxj_DPEnumConnectionsObject>;
  119. if (!pNew) return E_OUTOFMEMORY;
  120. pNew->m_bProblem=FALSE;
  121. hr = pdp->EnumConnections(pguid,
  122. myEnumConnectionsCallback,
  123. pNew, (long)flags);
  124. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  125. #pragma message ("make sure free on failure cleans up in enumerators on STrings and objects")
  126. if FAILED(hr)
  127. {
  128. //free(pNew->m_pList);
  129. //pNew->m_pList=NULL;
  130. //destructor will clean up properly
  131. delete pNew;
  132. return hr;
  133. }
  134. hr=pNew->QueryInterface(IID_I_dxj_DPEnumConnections,(void**)ppRet);
  135. return hr;
  136. }
  137. /* DEAD CODE
  138. HRESULT C_dxj_DPEnumConnectionsObject::getItem( long index, DPConnection *info)
  139. {
  140. if (m_pList==NULL) return E_FAIL;
  141. if (index < 0) return E_INVALIDARG;
  142. if (index >= m_nCount) return E_INVALIDARG;
  143. if (!info) return E_INVALIDARG;
  144. if (info->strGuid) SysFreeString((BSTR)info->strGuid);
  145. if (info->strShortName) SysFreeString((BSTR)info->strShortName);
  146. if (info->strLongName) SysFreeString((BSTR)info->strLongName);
  147. info->strGuid=SysAllocString(m_pList[index].strGuid);
  148. info->strShortName=SysAllocString(m_pList[index].strShortName);
  149. info->strLongName=SysAllocString(m_pList[index].strLongName);
  150. info->lFlags=m_pList[index].lFlags;
  151. return S_OK;
  152. }
  153. */
  154. HRESULT C_dxj_DPEnumConnectionsObject::getFlags( long index, long *retV)
  155. {
  156. if (m_pList==NULL) return E_FAIL;
  157. if (index < 1) return E_INVALIDARG;
  158. if (index > m_nCount) return E_INVALIDARG;
  159. *retV=m_pList[index-1].lFlags;
  160. return S_OK;
  161. }
  162. HRESULT C_dxj_DPEnumConnectionsObject::getGuid( long index, BSTR *retV)
  163. {
  164. if (m_pList==NULL) return E_FAIL;
  165. if (index < 1) return E_INVALIDARG;
  166. if (index > m_nCount) return E_INVALIDARG;
  167. *retV=SysAllocString(m_pList[index-1].strGuid);
  168. return S_OK;
  169. }
  170. HRESULT C_dxj_DPEnumConnectionsObject::getName( long index, BSTR *retV)
  171. {
  172. if (m_pList==NULL) return E_FAIL;
  173. if (index < 1) return E_INVALIDARG;
  174. if (index > m_nCount) return E_INVALIDARG;
  175. *retV=SysAllocString(m_pList[index-1].strShortName);
  176. return S_OK;
  177. }
  178. /*
  179. HRESULT C_dxj_DPEnumConnectionsObject::getLongName( long index, BSTR *retV)
  180. {
  181. if (m_pList==NULL) return E_FAIL;
  182. if (index < 1) return E_INVALIDARG;
  183. if (index > m_nCount) return E_INVALIDARG;
  184. *retV=SysAllocString(m_pList[index-1].strLongName);
  185. return S_OK;
  186. }
  187. */
  188. HRESULT C_dxj_DPEnumConnectionsObject::getAddress(long index,I_dxj_DPAddress **ppret){
  189. if (m_pList2==NULL) return E_FAIL;
  190. if (index < 1) return E_INVALIDARG;
  191. if (index > m_nCount) return E_INVALIDARG;
  192. if (m_pList2[index-1]==NULL) return E_FAIL;
  193. HRESULT hr=m_pList2[index-1]->QueryInterface(IID_I_dxj_DPAddress,(void**)ppret);
  194. return hr;
  195. }
  196. HRESULT C_dxj_DPEnumConnectionsObject::getCount(long *retVal)
  197. {
  198. *retVal=m_nCount;
  199. return S_OK;
  200. }