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.

172 lines
4.9 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright 1995 - 1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #ifndef _DATAOBJ_H
  9. #define _DATAOBJ_H
  10. class CDataObject : public IDataObject, public CComObjectRoot
  11. {
  12. friend class CSnapin;
  13. // ATL Maps
  14. DECLARE_NOT_AGGREGATABLE(CDataObject)
  15. BEGIN_COM_MAP(CDataObject)
  16. COM_INTERFACE_ENTRY(IDataObject)
  17. END_COM_MAP()
  18. // Construction/Destruction
  19. CDataObject();
  20. ~CDataObject()
  21. {
  22. #ifdef _DEBUG
  23. m_ComponentData = NULL;
  24. #endif
  25. delete [] m_pbMultiSelData;
  26. };
  27. // Clipboard formats that are required by the console
  28. public:
  29. static unsigned int m_cfNodeType; // Required by the console
  30. static unsigned int m_cfNodeTypeString; // Required by the console
  31. static unsigned int m_cfDisplayName; // Required by the console
  32. static unsigned int m_cfCoClass; // Required by the console
  33. static unsigned int m_cfMultiSel; // Required by the console
  34. static unsigned int m_cfNodeID; // Published information
  35. static unsigned int m_cfInternal; // Step 3
  36. static unsigned int m_cfWorkstation; // Published information
  37. // Standard IDataObject methods
  38. public:
  39. // Implemented
  40. STDMETHOD(GetData)(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium);
  41. STDMETHOD(GetDataHere)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium);
  42. STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc);
  43. ULONG InternalAddRef()
  44. {
  45. #ifdef _DEBUG
  46. ASSERT(m_ComponentData != NULL);
  47. ++(m_ComponentData->m_cDataObjects);
  48. if (m_bMultiSelDobj == TRUE)
  49. AddRefMultiSelDobj();
  50. #endif
  51. return CComObjectRoot::InternalAddRef();
  52. }
  53. ULONG InternalRelease()
  54. {
  55. #ifdef _DEBUG
  56. ASSERT(m_ComponentData != NULL);
  57. --(m_ComponentData->m_cDataObjects);
  58. if (m_bMultiSelDobj == TRUE)
  59. ReleaseMultiSelDobj();
  60. #endif
  61. return CComObjectRoot::InternalRelease();
  62. }
  63. // Not Implemented
  64. private:
  65. STDMETHOD(QueryGetData)(LPFORMATETC lpFormatetc)
  66. { return E_NOTIMPL; };
  67. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC lpFormatetcIn, LPFORMATETC lpFormatetcOut)
  68. { return E_NOTIMPL; };
  69. STDMETHOD(SetData)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease)
  70. { return E_NOTIMPL; };
  71. STDMETHOD(DAdvise)(LPFORMATETC lpFormatetc, DWORD advf,
  72. LPADVISESINK pAdvSink, LPDWORD pdwConnection)
  73. { return E_NOTIMPL; };
  74. STDMETHOD(DUnadvise)(DWORD dwConnection)
  75. { return E_NOTIMPL; };
  76. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA* ppEnumAdvise)
  77. { return E_NOTIMPL; };
  78. // Implementation
  79. public:
  80. void SetType(DATA_OBJECT_TYPES type) // Step 3
  81. { ASSERT(m_internal.m_type == CCT_UNINITIALIZED); m_internal.m_type = type; }
  82. // This is used only as a diagnostic in debug builds to track if
  83. // anyone is hanging on to any data objects that's have been handed out
  84. // Snapin's should view context data objects as ephemeral.
  85. #ifdef _DEBUG
  86. public:
  87. void SetComponentData(CComponentDataImpl* pCCD)
  88. {
  89. ASSERT(m_ComponentData == NULL && pCCD != NULL); m_ComponentData = pCCD;
  90. } ;
  91. private:
  92. CComponentDataImpl* m_ComponentData;
  93. #endif
  94. public:
  95. void SetCookie(MMC_COOKIE cookie) { m_internal.m_cookie = cookie; } // Step 3
  96. void SetString(LPTSTR lpString) { m_internal.m_string = lpString; }
  97. void SetClsid(const CLSID& clsid) { m_internal.m_clsid = clsid; }
  98. void SetMultiSelData(BYTE* pbMultiSelData, UINT cbMultiSelData)
  99. {
  100. m_pbMultiSelData = pbMultiSelData;
  101. m_cbMultiSelData = cbMultiSelData;
  102. }
  103. void SetMultiSelDobj()
  104. {
  105. m_bMultiSelDobj = TRUE;
  106. }
  107. BOOL IsMultiSelDobj()
  108. {
  109. return m_bMultiSelDobj;
  110. }
  111. #ifdef _DEBUG
  112. UINT dbg_refCount;
  113. void AddRefMultiSelDobj()
  114. {
  115. ASSERT(m_bMultiSelDobj == TRUE);
  116. ++dbg_refCount;
  117. }
  118. void ReleaseMultiSelDobj()
  119. {
  120. ASSERT(m_bMultiSelDobj == TRUE);
  121. --dbg_refCount;
  122. //if (dbg_refCount == 0)
  123. // ::MessageBox(NULL, _T("Final release on multi-sel-dobj"), _T("Sample snapin"), MB_OK);
  124. }
  125. #endif
  126. private:
  127. HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium);
  128. HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium);
  129. HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium);
  130. HRESULT CreateInternal(LPSTGMEDIUM lpMedium); // Step 3
  131. HRESULT CreateWorkstationName(LPSTGMEDIUM lpMedium);
  132. HRESULT CreateCoClassID(LPSTGMEDIUM lpMedium);
  133. HRESULT CreateMultiSelData(LPSTGMEDIUM lpMedium);
  134. HRESULT Create(const void* pBuffer, int len, LPSTGMEDIUM lpMedium);
  135. INTERNAL m_internal; // Step 3
  136. BYTE* m_pbMultiSelData;
  137. UINT m_cbMultiSelData;
  138. BOOL m_bMultiSelDobj;
  139. };
  140. #endif