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.

178 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumlocalapplicationsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DPEnumLocalApplicationsObj.h"
  14. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  15. extern HRESULT DPLBSTRtoPPGUID(LPGUID *,BSTR);
  16. /////////////////////////////////////////////////////////////////////////////
  17. /////////////////////////////////////////////////////////////////////////////
  18. /////////////////////////////////////////////////////////////////////////////
  19. extern "C" BOOL PASCAL objEnumLocalApplicationsCallback(
  20. LPCDPLAPPINFO lpAppInfo,
  21. LPVOID lpArg, DWORD dwFlags)
  22. {
  23. DPF(1,"Entered objEnumLocalApplicationsCallback\r\n");
  24. C_dxj_DPEnumLocalApplicationsObject *pObj=(C_dxj_DPEnumLocalApplicationsObject*)lpArg;
  25. if (pObj==NULL) return TRUE;
  26. if (pObj->m_nCount >= pObj->m_nMax)
  27. {
  28. pObj->m_nMax += 10;
  29. if (pObj->m_pList)
  30. pObj->m_pList=(DPLAppInfo*)realloc(pObj->m_pList,sizeof(DPLAppInfo)* pObj->m_nMax);
  31. else
  32. pObj->m_pList=(DPLAppInfo*)malloc(sizeof(DPLAppInfo)* pObj->m_nMax);
  33. if (pObj->m_pList==NULL)
  34. {
  35. pObj->m_bProblem=TRUE;
  36. return FALSE;
  37. }
  38. }
  39. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPLAppInfo));
  40. if (!lpAppInfo) {
  41. pObj->m_bProblem=TRUE;
  42. return FALSE;
  43. }
  44. pObj->m_pList[pObj->m_nCount].strGuidApplication= DPLGUIDtoBSTR((GUID*)&(lpAppInfo->guidApplication));
  45. if (lpAppInfo->lpszAppName)
  46. pObj->m_pList[pObj->m_nCount].strAppName = SysAllocString(lpAppInfo->lpszAppName);
  47. //pObj->m_pList[pObj->m_nCount].lFlags=(DWORD)dwFlags;
  48. pObj->m_nCount++;
  49. return TRUE;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. C_dxj_DPEnumLocalApplicationsObject::C_dxj_DPEnumLocalApplicationsObject()
  53. {
  54. m_nMax=0;
  55. m_pList=NULL;
  56. m_nCount=0;
  57. m_bProblem=FALSE;
  58. }
  59. C_dxj_DPEnumLocalApplicationsObject::~C_dxj_DPEnumLocalApplicationsObject()
  60. {
  61. //empty list
  62. if (m_pList){
  63. for (int i=0;i<m_nCount;i++)
  64. {
  65. DPLAppInfo *conn=&(m_pList[i]);
  66. if (conn->strGuidApplication ) SysFreeString(conn->strGuidApplication);
  67. if (conn->strAppName) SysFreeString(conn->strAppName);
  68. }
  69. free(m_pList);
  70. }
  71. }
  72. HRESULT C_dxj_DPEnumLocalApplicationsObject::create(
  73. IDirectPlayLobby3 * pdp,
  74. long flags, I_dxj_DPEnumLocalApplications **ppRet)
  75. {
  76. HRESULT hr;
  77. C_dxj_DPEnumLocalApplicationsObject *pNew=NULL;
  78. *ppRet=NULL;
  79. pNew= new CComObject<C_dxj_DPEnumLocalApplicationsObject>;
  80. if (!pNew) return E_OUTOFMEMORY;
  81. pNew->m_bProblem=FALSE;
  82. hr = pdp->EnumLocalApplications(
  83. objEnumLocalApplicationsCallback,
  84. pNew, (DWORD)flags);
  85. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  86. if FAILED(hr)
  87. {
  88. delete pNew;
  89. return hr;
  90. }
  91. hr=pNew->QueryInterface(IID_I_dxj_DPEnumLocalApplications,(void**)ppRet);
  92. return hr;
  93. }
  94. HRESULT C_dxj_DPEnumLocalApplicationsObject::getName( long index, BSTR __RPC_FAR *ret)
  95. {
  96. if (m_pList==NULL) return E_FAIL;
  97. if (index < 1) return E_INVALIDARG;
  98. if (index > m_nCount) return E_INVALIDARG;
  99. *ret=SysAllocString(m_pList[index-1].strAppName);
  100. return S_OK;
  101. }
  102. HRESULT C_dxj_DPEnumLocalApplicationsObject::getGuid( long index, BSTR __RPC_FAR *ret)
  103. {
  104. if (m_pList==NULL) return E_FAIL;
  105. if (index < 1) return E_INVALIDARG;
  106. if (index > m_nCount) return E_INVALIDARG;
  107. *ret=SysAllocString(m_pList[index-1].strGuidApplication);
  108. return S_OK;
  109. }
  110. /*
  111. HRESULT C_dxj_DPEnumLocalApplicationsObject::getItem( long index, DPLAppInfo *info)
  112. {
  113. if (m_pList==NULL) return E_FAIL;
  114. if (index < 0) return E_INVALIDARG;
  115. if (index >= m_nCount) return E_INVALIDARG;
  116. memcpy(info,&(m_pList[index]),sizeof(DPLAppInfo));
  117. if (info->strGuidApplication) SysFreeString(info->strGuidApplication);
  118. if (info->strAppName) SysFreeString(info->strAppName);
  119. info->strAppName=SysAllocString(info->strAppName);
  120. info->strGuidApplication=SysAllocString(info->strGuidApplication);
  121. return S_OK;
  122. }
  123. */
  124. HRESULT C_dxj_DPEnumLocalApplicationsObject::getCount(long *retVal)
  125. {
  126. *retVal=m_nCount;
  127. return S_OK;
  128. }