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.

270 lines
4.2 KiB

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