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.

269 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. mapcol.h
  5. Abstract:
  6. Mapping 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(CMappings, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CMappings, CCmdTarget)
  21. //{{AFX_MSG_MAP(CMappings)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CMappings, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CMappings)
  27. DISP_PROPERTY_EX(CMappings, "Count", GetCount, SetNotSupported, VT_I4)
  28. DISP_PROPERTY_EX(CMappings, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CMappings, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  30. DISP_FUNCTION(CMappings, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
  31. //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33. CMappings::CMappings(CCmdTarget* pParent, CObArray* pObArray)
  34. /*++
  35. Routine Description:
  36. Constructor for mapping 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(CController)));
  47. #endif // ENABLE_PARENT_CHECK
  48. ASSERT_VALID(pObArray);
  49. m_pParent = pParent;
  50. m_pObArray = pObArray;
  51. }
  52. CMappings::~CMappings()
  53. /*++
  54. Routine Description:
  55. Destructor for mapping collection object.
  56. Arguments:
  57. None.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. //
  63. // Nothing to do here.
  64. //
  65. }
  66. void CMappings::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 CMappings::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 CMappings::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 CMappings::GetItem(const VARIANT FAR& index)
  105. /*++
  106. Routine Description:
  107. Retrieves specified mapping object from collection.
  108. Arguments:
  109. index - optional argument that may be a string (VT_BSTR)
  110. indicating a mapping name or a number (VT_I4) indicating
  111. the position within collection.
  112. Return Values:
  113. VT_DISPATCH.
  114. --*/
  115. {
  116. ASSERT_VALID(m_pObArray);
  117. LPDISPATCH lpdispatch = NULL;
  118. CMapping* pMapping;
  119. INT_PTR iMapping;
  120. VARIANT vMapping;
  121. VariantInit(&vMapping);
  122. iMapping = m_pObArray->GetSize();
  123. if (NULL != iMapping)
  124. {
  125. if (index.vt == VT_BSTR)
  126. {
  127. while (iMapping--)
  128. {
  129. pMapping = (CMapping*)m_pObArray->GetAt(iMapping);
  130. if (NULL != pMapping)
  131. {
  132. ASSERT(pMapping->IsKindOf(RUNTIME_CLASS(CMapping)));
  133. if (!pMapping->m_strName.CompareNoCase(index.bstrVal))
  134. {
  135. lpdispatch = pMapping->GetIDispatch(TRUE);
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. else if (SUCCEEDED(VariantChangeType(&vMapping, (VARIANT FAR *)&index, 0, VT_I4)))
  142. {
  143. if (((int)vMapping.lVal >= 0) && ((int)vMapping.lVal < iMapping))
  144. {
  145. pMapping = (CMapping*)m_pObArray->GetAt((int)vMapping.lVal);
  146. if (NULL != pMapping)
  147. {
  148. ASSERT(pMapping->IsKindOf(RUNTIME_CLASS(CMapping)));
  149. lpdispatch = pMapping->GetIDispatch(TRUE);
  150. }
  151. }
  152. }
  153. }
  154. return lpdispatch;
  155. }
  156. LPDISPATCH CMappings::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. }