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.

160 lines
3.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // Componentimpl.h : implementation helper template for component interface
  3. // Copyright (c) Microsoft Corporation 1999.
  4. #ifndef COMPONENTIMPL_H
  5. #define COMPONENTIMPL_H
  6. #include "componenttype.h"
  7. namespace BDATuningModel {
  8. template<class T,
  9. class MostDerived = IComponent,
  10. LPCGUID iid = &__uuidof(MostDerived),
  11. LPCGUID LibID = &LIBID_TunerLib,
  12. WORD wMajor = 1,
  13. WORD wMinor = 0,
  14. class tihclass = CComTypeInfoHolder
  15. > class ATL_NO_VTABLE IComponentImpl :
  16. public IPersistPropertyBagImpl<T>,
  17. public IDispatchImpl<MostDerived, iid, LibID, wMajor, wMinor, tihclass>
  18. {
  19. // IComponent
  20. public:
  21. PQComponentType m_Type;
  22. CComBSTR m_Desc;
  23. ComponentStatus m_ComponentStatus;
  24. long m_DescLangID;
  25. IComponentImpl() : m_ComponentStatus(StatusUnavailable),
  26. m_DescLangID(-1) {}
  27. virtual ~IComponentImpl() {}
  28. typedef IComponentImpl<T, MostDerived, iid, LibID, wMajor, wMinor, tihclass> thistype;
  29. BEGIN_PROP_MAP(thistype)
  30. PROP_DATA_QI_ENTRY("Type", m_Type.p, __uuidof(IComponentType))
  31. PROP_DATA_ENTRY("Description", m_Desc.m_str, VT_BSTR)
  32. PROP_DATA_ENTRY("DescLangID", m_DescLangID, VT_I4)
  33. PROP_DATA_ENTRY("Status", m_ComponentStatus, VT_I4)
  34. END_PROP_MAP()
  35. // IComponent
  36. public:
  37. STDMETHOD(get_Type)(/*[out, retval]*/ IComponentType** ppVal) {
  38. try {
  39. if (!ppVal) {
  40. return E_POINTER;
  41. }
  42. ATL_LOCKT();
  43. return m_Type.CopyTo(ppVal);
  44. } catch (...) {
  45. return E_POINTER;
  46. }
  47. }
  48. STDMETHOD(put_Type)(/*[in]*/ IComponentType* pNewVal) {
  49. ATL_LOCKT();
  50. m_Type = pNewVal;
  51. MARK_DIRTY(T);
  52. return NOERROR;
  53. }
  54. STDMETHOD(get_Description)(/*[out, retval]*/ BSTR *pVal) {
  55. try {
  56. ATL_LOCKT();
  57. return m_Desc.CopyTo(pVal);
  58. } catch (...) {
  59. return E_POINTER;
  60. }
  61. }
  62. STDMETHOD(put_Description)(/*[in]*/ BSTR newVal) {
  63. try {
  64. CHECKBSTRLIMIT(newVal);
  65. ATL_LOCKT();
  66. m_Desc = newVal;
  67. MARK_DIRTY(T);
  68. } catch (...) {
  69. return E_POINTER;
  70. }
  71. return NOERROR;
  72. }
  73. STDMETHOD(get_DescLangID)(/*[out, retval]*/ long *pLangID) {
  74. try {
  75. if (!pLangID) {
  76. return E_POINTER;
  77. }
  78. ATL_LOCKT();
  79. *pLangID = m_DescLangID;
  80. return NOERROR;
  81. } catch (...) {
  82. return E_POINTER;
  83. }
  84. }
  85. STDMETHOD(put_DescLangID)(/*[in]*/ long NewLangID) {
  86. ATL_LOCKT();
  87. m_DescLangID = NewLangID;
  88. MARK_DIRTY(T);
  89. return NOERROR;
  90. }
  91. STDMETHOD(get_Status)(/*[out, retval]*/ ComponentStatus *pVal) {
  92. try {
  93. if (!pVal) {
  94. return E_POINTER;
  95. }
  96. ATL_LOCKT();
  97. *pVal = m_ComponentStatus;
  98. } catch (...) {
  99. return E_POINTER;
  100. }
  101. return NOERROR;
  102. }
  103. STDMETHOD(put_Status)(/*[in]*/ ComponentStatus newVal) {
  104. ATL_LOCKT();
  105. m_ComponentStatus = newVal;
  106. MARK_DIRTY(T);
  107. return NOERROR;
  108. }
  109. STDMETHOD(Clone)(/*[out, retval]*/ IComponent **ppNew) {
  110. try {
  111. if (!ppNew) {
  112. return E_POINTER;
  113. }
  114. ATL_LOCKT();
  115. T* pt = static_cast<T*>(new CComObject<T>);
  116. if (!pt) {
  117. return E_OUTOFMEMORY;
  118. }
  119. if(m_Type){
  120. ASSERT(!pt->m_Type);
  121. HRESULT hr = m_Type->Clone(&pt->m_Type);
  122. if (FAILED(hr)) {
  123. delete pt;
  124. return hr;
  125. }
  126. }
  127. pt->AddRef();
  128. pt->m_Desc = m_Desc.Copy();
  129. pt->m_DescLangID = m_DescLangID;
  130. pt->m_ComponentStatus = m_ComponentStatus;
  131. pt->m_bRequiresSave = true;
  132. *ppNew = pt;
  133. return NOERROR;
  134. } catch (HRESULT h) {
  135. return h;
  136. } catch (...) {
  137. return E_POINTER;
  138. }
  139. return NOERROR;
  140. }
  141. };
  142. }; // namespace
  143. #endif // COMPONENTIMPL_H
  144. // end of file -- componentimpl.h