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.

182 lines
5.3 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: NoticeNumbers.cpp
  4. Contents: Implementation of CNoticeNumbers class for collection of
  5. IExtension objects.
  6. Remarks: This object is not creatable by user directly. It can only be
  7. created via property/method of other CAPICOM objects.
  8. The collection container is implemented usign STL::map of
  9. STL::pair of BSTR and IExtension..
  10. See Chapter 9 of "BEGINNING ATL 3 COM Programming" for algorithm
  11. adopted in here.
  12. History: 06-15-2001 dsie created
  13. ------------------------------------------------------------------------------*/
  14. #include "StdAfx.h"
  15. #include "CAPICOM.h"
  16. #include "NoticeNumbers.h"
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Exported functions.
  20. //
  21. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  22. Function : CreateNoticeNumbersObject
  23. Synopsis : Create an INoticeNumbers collection object, and load the object
  24. with NoticeNumbers.
  25. Parameter: PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE pNoticeReference
  26. INoticeNumbers ** ppINoticeNumbers - Pointer to pointer
  27. INoticeNumbers to recieve the
  28. interface pointer.
  29. Remark :
  30. ------------------------------------------------------------------------------*/
  31. HRESULT CreateNoticeNumbersObject (PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE pNoticeReference,
  32. INoticeNumbers ** ppINoticeNumbers)
  33. {
  34. HRESULT hr = S_OK;
  35. CComObject<CNoticeNumbers> * pCNoticeNumbers = NULL;
  36. DebugTrace("Entering CreateNoticeNumbersObject().\n");
  37. //
  38. // Sanity check.
  39. //
  40. ATLASSERT(pNoticeReference);
  41. ATLASSERT(ppINoticeNumbers);
  42. try
  43. {
  44. //
  45. // Create the object. Note that the ref count will still be 0
  46. // after the object is created.
  47. //
  48. if (FAILED(hr = CComObject<CNoticeNumbers>::CreateInstance(&pCNoticeNumbers)))
  49. {
  50. DebugTrace("Error [%#x]: CComObject<CNoticeNumbers>::CreateInstance() failed.\n", hr);
  51. goto ErrorExit;
  52. }
  53. //
  54. // Init object with notice numbers.
  55. //
  56. if (FAILED(hr = pCNoticeNumbers->Init(pNoticeReference->cNoticeNumbers,
  57. pNoticeReference->rgNoticeNumbers)))
  58. {
  59. DebugTrace("Error [%#x]: pCNoticeNumbers->Init() failed.\n", hr);
  60. goto ErrorExit;
  61. }
  62. //
  63. // Return interface pointer to caller.
  64. //
  65. if (FAILED(hr = pCNoticeNumbers->QueryInterface(ppINoticeNumbers)))
  66. {
  67. DebugTrace("Error [%#x]: pCNoticeNumbers->QueryInterface() failed.\n", hr);
  68. goto ErrorExit;
  69. }
  70. }
  71. catch(...)
  72. {
  73. hr = E_POINTER;
  74. DebugTrace("Exception: invalid parameter.\n");
  75. goto ErrorExit;
  76. }
  77. CommonExit:
  78. DebugTrace("Leaving CreateNoticeNumbersObject().\n");
  79. return hr;
  80. ErrorExit:
  81. //
  82. // Sanity check.
  83. //
  84. ATLASSERT(FAILED(hr));
  85. //
  86. // Free resource.
  87. //
  88. if (pCNoticeNumbers)
  89. {
  90. delete pCNoticeNumbers;
  91. }
  92. goto CommonExit;
  93. }
  94. ////////////////////////////////////////////////////////////////////////////////
  95. //
  96. // CNoticeNumbers
  97. //
  98. ////////////////////////////////////////////////////////////////////////////////
  99. //
  100. // Non COM functions.
  101. //
  102. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  103. Function : CNoticeNumbers::Init
  104. Synopsis : Load all extensions into the collection.
  105. Parameter: DWORD cNoticeNumbers - Number of extensions.
  106. int * rgNoticeNumbers - Array of extensions.
  107. Remark : This method is not part of the COM interface (it is a normal C++
  108. member function). We need it to initialize the object created
  109. internally by us.
  110. Since it is only a normal C++ member function, this function can
  111. only be called from a C++ class pointer, not an interface pointer.
  112. ------------------------------------------------------------------------------*/
  113. STDMETHODIMP CNoticeNumbers::Init (DWORD cNoticeNumbers,
  114. int * rgNoticeNumbers)
  115. {
  116. HRESULT hr = S_OK;
  117. DebugTrace("Entering CNoticeNumbers::Init().\n");
  118. //
  119. // Add all to the collection.
  120. //
  121. for (DWORD i = 0; i < cNoticeNumbers; i++)
  122. {
  123. //
  124. // Now add object to collection vector.
  125. //
  126. // Note that the overloaded = operator for CComPtr will
  127. // automatically AddRef to the object. Also, when the CComPtr
  128. // is deleted (happens when the Remove or map destructor is called),
  129. // the CComPtr destructor will automatically Release the object.
  130. //
  131. m_coll.push_back((long) rgNoticeNumbers[i]);
  132. }
  133. DebugTrace("Leaving CNoticeNumbers::Init().\n");
  134. return hr;
  135. }