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