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.

184 lines
4.4 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. {
  31. void* tmp = realloc(pObj->m_pList,sizeof(DPLAppInfo)* pObj->m_nMax);
  32. if (tmp)
  33. pObj->m_pList=(DPLAppInfo*)tmp;
  34. else
  35. return FALSE;
  36. }
  37. else
  38. pObj->m_pList=(DPLAppInfo*)malloc(sizeof(DPLAppInfo)* pObj->m_nMax);
  39. if (pObj->m_pList==NULL)
  40. {
  41. pObj->m_bProblem=TRUE;
  42. return FALSE;
  43. }
  44. }
  45. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPLAppInfo));
  46. if (!lpAppInfo) {
  47. pObj->m_bProblem=TRUE;
  48. return FALSE;
  49. }
  50. pObj->m_pList[pObj->m_nCount].strGuidApplication= DPLGUIDtoBSTR((GUID*)&(lpAppInfo->guidApplication));
  51. if (lpAppInfo->lpszAppName)
  52. pObj->m_pList[pObj->m_nCount].strAppName = SysAllocString(lpAppInfo->lpszAppName);
  53. //pObj->m_pList[pObj->m_nCount].lFlags=(DWORD)dwFlags;
  54. pObj->m_nCount++;
  55. return TRUE;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. C_dxj_DPEnumLocalApplicationsObject::C_dxj_DPEnumLocalApplicationsObject()
  59. {
  60. m_nMax=0;
  61. m_pList=NULL;
  62. m_nCount=0;
  63. m_bProblem=FALSE;
  64. }
  65. C_dxj_DPEnumLocalApplicationsObject::~C_dxj_DPEnumLocalApplicationsObject()
  66. {
  67. //empty list
  68. if (m_pList){
  69. for (int i=0;i<m_nCount;i++)
  70. {
  71. DPLAppInfo *conn=&(m_pList[i]);
  72. if (conn->strGuidApplication ) SysFreeString((BSTR)conn->strGuidApplication);
  73. if (conn->strAppName) SysFreeString((BSTR)conn->strAppName);
  74. }
  75. free(m_pList);
  76. }
  77. }
  78. HRESULT C_dxj_DPEnumLocalApplicationsObject::create(
  79. IDirectPlayLobby3 * pdp,
  80. long flags, I_dxj_DPEnumLocalApplications **ppRet)
  81. {
  82. HRESULT hr;
  83. C_dxj_DPEnumLocalApplicationsObject *pNew=NULL;
  84. *ppRet=NULL;
  85. pNew= new CComObject<C_dxj_DPEnumLocalApplicationsObject>;
  86. if (!pNew) return E_OUTOFMEMORY;
  87. pNew->m_bProblem=FALSE;
  88. hr = pdp->EnumLocalApplications(
  89. objEnumLocalApplicationsCallback,
  90. pNew, (DWORD)flags);
  91. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  92. if FAILED(hr)
  93. {
  94. delete pNew;
  95. return hr;
  96. }
  97. hr=pNew->QueryInterface(IID_I_dxj_DPEnumLocalApplications,(void**)ppRet);
  98. return hr;
  99. }
  100. HRESULT C_dxj_DPEnumLocalApplicationsObject::getName( long index, BSTR __RPC_FAR *ret)
  101. {
  102. if (m_pList==NULL) return E_FAIL;
  103. if (index < 1) return E_INVALIDARG;
  104. if (index > m_nCount) return E_INVALIDARG;
  105. *ret=SysAllocString(m_pList[index-1].strAppName);
  106. return S_OK;
  107. }
  108. HRESULT C_dxj_DPEnumLocalApplicationsObject::getGuid( long index, BSTR __RPC_FAR *ret)
  109. {
  110. if (m_pList==NULL) return E_FAIL;
  111. if (index < 1) return E_INVALIDARG;
  112. if (index > m_nCount) return E_INVALIDARG;
  113. *ret=SysAllocString(m_pList[index-1].strGuidApplication);
  114. return S_OK;
  115. }
  116. /*
  117. HRESULT C_dxj_DPEnumLocalApplicationsObject::getItem( long index, DPLAppInfo *info)
  118. {
  119. if (m_pList==NULL) return E_FAIL;
  120. if (index < 0) return E_INVALIDARG;
  121. if (index >= m_nCount) return E_INVALIDARG;
  122. memcpy(info,&(m_pList[index]),sizeof(DPLAppInfo));
  123. if (info->strGuidApplication) SysFreeString((BSTR)info->strGuidApplication);
  124. if (info->strAppName) SysFreeString((BSTR)info->strAppName);
  125. info->strAppName=SysAllocString(info->strAppName);
  126. info->strGuidApplication=SysAllocString(info->strGuidApplication);
  127. return S_OK;
  128. }
  129. */
  130. HRESULT C_dxj_DPEnumLocalApplicationsObject::getCount(long *retVal)
  131. {
  132. *retVal=m_nCount;
  133. return S_OK;
  134. }