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.

268 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. svccol.cpp
  5. Abstract:
  6. Service collection object implementation.
  7. Author:
  8. Don Ryan (donryan) 04-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CServices, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CServices, CCmdTarget)
  21. //{{AFX_MSG_MAP(CServices)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CServices, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CServices)
  27. DISP_PROPERTY_EX(CServices, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  28. DISP_PROPERTY_EX(CServices, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CServices, "Count", GetCount, SetNotSupported, VT_I4)
  30. DISP_FUNCTION(CServices, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
  31. //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33. CServices::CServices(CCmdTarget* pParent, CObArray* pObArray)
  34. /*++
  35. Routine Description:
  36. Constructor for service collection object.
  37. Arguments:
  38. pParent - creator of object.
  39. pObArray - object list to enumerate.
  40. Return Values:
  41. None.
  42. --*/
  43. {
  44. EnableAutomation();
  45. #ifdef ENABLE_PARENT_CHECK
  46. ASSERT(pParent && pParent->IsKindOf(RUNTIME_CLASS(CServer)));
  47. #endif // ENABLE_PARENT_CHECK
  48. ASSERT_VALID(pObArray);
  49. m_pParent = pParent;
  50. m_pObArray = pObArray;
  51. }
  52. CServices::~CServices()
  53. /*++
  54. Routine Description:
  55. Destructor for service collection object.
  56. Arguments:
  57. None.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. //
  63. // Nothing to do here.
  64. //
  65. }
  66. void CServices::OnFinalRelease()
  67. /*++
  68. Routine Description:
  69. When the last reference for an automation object is released
  70. OnFinalRelease is called. This implementation deletes object.
  71. Arguments:
  72. None.
  73. Return Values:
  74. None.
  75. --*/
  76. {
  77. delete this;
  78. }
  79. LPDISPATCH CServices::GetApplication()
  80. /*++
  81. Routine Description:
  82. Returns the application object.
  83. Arguments:
  84. None.
  85. Return Values:
  86. VT_DISPATCH.
  87. --*/
  88. {
  89. return theApp.GetAppIDispatch();
  90. }
  91. long CServices::GetCount()
  92. /*++
  93. Routine Description:
  94. Returns number of items in collection.
  95. Arguments:
  96. None.
  97. Return Values:
  98. VT_I4.
  99. --*/
  100. {
  101. ASSERT_VALID(m_pObArray);
  102. return (long)m_pObArray->GetSize();
  103. }
  104. LPDISPATCH CServices::GetItem(const VARIANT FAR& index)
  105. /*++
  106. Routine Description:
  107. Retrieves specified service object from collection.
  108. Arguments:
  109. index - optional argument that may be a string (VT_BSTR)
  110. indicating the service name or a number (VT_I4) indicating
  111. the position within collection.
  112. Return Values:
  113. VT_DISPATCH or VT_EMPTY.
  114. --*/
  115. {
  116. ASSERT_VALID(m_pObArray);
  117. LPDISPATCH lpdispatch = NULL;
  118. CService* pService;
  119. INT_PTR iService;
  120. VARIANT vService;
  121. VariantInit(&vService);
  122. if (iService = m_pObArray->GetSize())
  123. {
  124. if (index.vt == VT_BSTR)
  125. {
  126. while (iService--)
  127. {
  128. if (pService = (CService*)m_pObArray->GetAt(iService))
  129. {
  130. ASSERT(pService->IsKindOf(RUNTIME_CLASS(CService)));
  131. if (!pService->m_strName.CompareNoCase(index.bstrVal))
  132. {
  133. lpdispatch = pService->GetIDispatch(TRUE);
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. else if (SUCCEEDED(VariantChangeType(&vService, (VARIANT FAR *)&index, 0, VT_I4)))
  140. {
  141. if (((int)vService.lVal >= 0) && ((int)vService.lVal < iService))
  142. {
  143. if (pService = (CService*)m_pObArray->GetAt((int)vService.lVal))
  144. {
  145. ASSERT(pService->IsKindOf(RUNTIME_CLASS(CService)));
  146. lpdispatch = pService->GetIDispatch(TRUE);
  147. }
  148. }
  149. }
  150. }
  151. return lpdispatch;
  152. }
  153. LPDISPATCH CServices::GetParent()
  154. /*++
  155. Routine Description:
  156. Returns the parent of the object.
  157. Arguments:
  158. None.
  159. Return Values:
  160. VT_DISPATCH.
  161. --*/
  162. {
  163. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  164. }