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.

210 lines
4.5 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows
  3. Copyright (C) Microsoft Corporation, 1995 - 1999
  4. File: CopyItem.h
  5. Content: Declaration of _CopyXXXItem template class.
  6. History: 11-15-99 dsie created
  7. ------------------------------------------------------------------------------*/
  8. #ifndef __CopyItem_H_
  9. #define __CopyItem_H_
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif // _MSC_VER > 1000
  13. #include <map>
  14. #pragma warning(disable:4786) // Disable symbol names > 256 character warning.
  15. //
  16. // _CopyMapItem class.
  17. //
  18. template <class T>
  19. class _CopyMapItem
  20. {
  21. public:
  22. //
  23. // copy method.
  24. //
  25. static HRESULT copy(VARIANT * p1, std::pair<const CComBSTR, CComPtr<T> > * p2)
  26. {
  27. CComPtr<T> p = p2->second;
  28. CComVariant var = p;
  29. return VariantCopy(p1, &var);
  30. }
  31. //
  32. // init method.
  33. //
  34. static void init(VARIANT * p)
  35. {
  36. p->vt = VT_EMPTY;
  37. }
  38. //
  39. // destroy method.
  40. //
  41. static void destroy(VARIANT * p)
  42. {
  43. VariantClear(p);
  44. }
  45. };
  46. //
  47. // _CopyBstrMap class.
  48. //
  49. class _CopyClsIdMap
  50. {
  51. public:
  52. //
  53. // copy method.
  54. //
  55. static HRESULT copy(VARIANT * p1, std::pair<const CComBSTR, const CLSID *> * p2)
  56. {
  57. HRESULT hr;
  58. CComPtr<IDispatch> p;
  59. //
  60. // Create the decoder object.
  61. //
  62. if (S_OK == (hr = ::CoCreateInstance((REFCLSID) p2->second,
  63. NULL,
  64. CLSCTX_INPROC_SERVER,
  65. IID_IDispatch,
  66. (LPVOID *) &p)))
  67. {
  68. //
  69. // Copy.
  70. //
  71. p1->vt = VT_DISPATCH;
  72. hr = p->QueryInterface((IDispatch **) &(p1->pdispVal));
  73. }
  74. return hr;
  75. }
  76. //
  77. // init method.
  78. //
  79. static void init(VARIANT * p)
  80. {
  81. p->vt = VT_EMPTY;
  82. }
  83. //
  84. // destroy method.
  85. //
  86. static void destroy(VARIANT * p)
  87. {
  88. VariantClear(p);
  89. }
  90. };
  91. template <class T>
  92. class _CopyVariant
  93. {
  94. public:
  95. //
  96. // init method.
  97. //
  98. static void init(VARIANT * p)
  99. {
  100. p->vt = VT_EMPTY;
  101. }
  102. //
  103. // copy method.
  104. //
  105. static HRESULT copy(VARIANT * p1, T * p2)
  106. {
  107. CComVariant var = *p2;
  108. return VariantCopy(p1, &var);
  109. }
  110. //
  111. // destroy method.
  112. //
  113. static void destroy(VARIANT * p)
  114. {
  115. VariantClear(p);
  116. }
  117. };
  118. #if (0) //DSIE
  119. template <class DestinationType, class SourceType = DestinationType>
  120. class GenericCopy
  121. {
  122. public :
  123. typedef DestinationType destination_type;
  124. typedef SourceType source_type;
  125. static void init(destination_type* p)
  126. {
  127. _Copy<destination_type>::init(p);
  128. }
  129. static void destroy(destination_type* p)
  130. {
  131. _Copy<destination_type>::destroy(p);
  132. }
  133. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  134. {
  135. return _Copy<destination_type>::copy(pTo, const_cast<source_type*>(pFrom));
  136. }
  137. }; // class GenericCopy
  138. template <>
  139. class GenericCopy<VARIANT, std::string>
  140. {
  141. public :
  142. typedef VARIANT destination_type;
  143. typedef std::string source_type;
  144. static void init(destination_type* p)
  145. {
  146. GenericCopy<destination_type>::init(p);
  147. }
  148. static void destroy(destination_type* p)
  149. {
  150. GenericCopy<destination_type>::destroy(p);
  151. }
  152. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  153. {
  154. return CComVariant(pFrom->c_str()).Detach(pTo);
  155. }
  156. }; // class GenericCopy<VARIANT, std::string>
  157. template <>
  158. class GenericCopy<BSTR, std::string>
  159. {
  160. public :
  161. typedef BSTR destination_type;
  162. typedef std::string source_type;
  163. static void init(destination_type* p)
  164. {
  165. GenericCopy<destination_type>::init(p);
  166. }
  167. static void destroy(destination_type* p)
  168. {
  169. GenericCopy<destination_type>::destroy(p);
  170. }
  171. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  172. {
  173. *pTo = CComBSTR(pFrom->c_str()).Detach();
  174. if (*pTo)
  175. return S_OK;
  176. else
  177. return E_OUTOFMEMORY;
  178. }
  179. }; // class GenericCopy<BSTR, std::string>
  180. #endif //DSIE
  181. #endif // __CopyItem_H_