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.

193 lines
5.1 KiB

  1. // Implements Mounted Volume
  2. #include "shellprv.h"
  3. #include "clsobj.h"
  4. EXTERN_C CLIPFORMAT g_cfMountedVolume = 0;
  5. class CMountedVolume : public IMountedVolume, IDataObject
  6. {
  7. public:
  8. //IUnknown methods
  9. STDMETHODIMP QueryInterface(REFIID,void **);
  10. STDMETHODIMP_(ULONG) AddRef(void);
  11. STDMETHODIMP_(ULONG) Release(void);
  12. //IDataObject methods
  13. STDMETHODIMP GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
  14. STDMETHODIMP GetDataHere(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
  15. STDMETHODIMP QueryGetData(LPFORMATETC pformatetcIn);
  16. STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut);
  17. STDMETHODIMP SetData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease);
  18. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppenumFormatEtc);
  19. STDMETHODIMP DAdvise(FORMATETC *pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD *pdwConnection);
  20. STDMETHODIMP DUnadvise(DWORD dwConnection);
  21. STDMETHODIMP EnumDAdvise(LPENUMSTATDATA *ppenumAdvise);
  22. // IMountedVolume methods
  23. STDMETHODIMP Initialize(LPCWSTR pcszMountPoint);
  24. protected:
  25. CMountedVolume();
  26. ~CMountedVolume();
  27. friend HRESULT CMountedVolume_CreateInstance(IUnknown* pUnkOuter, REFIID riid, void **ppv);
  28. private:
  29. LONG _cRef;
  30. TCHAR _szMountPoint[MAX_PATH];
  31. };
  32. //constructor/destructor and related functions
  33. CMountedVolume::CMountedVolume() :
  34. _cRef(1)
  35. {
  36. _szMountPoint[0] = 0;
  37. DllAddRef();
  38. }
  39. CMountedVolume::~CMountedVolume()
  40. {
  41. DllRelease();
  42. }
  43. STDAPI CMountedVolume_CreateInstance(IUnknown* pUnkOuter, REFIID riid, void **ppv)
  44. {
  45. HRESULT hr = E_OUTOFMEMORY;
  46. *ppv = NULL;
  47. if (!g_cfMountedVolume)
  48. g_cfMountedVolume = (CLIPFORMAT)RegisterClipboardFormat(CFSTR_MOUNTEDVOLUME);
  49. // aggregation checking is handled in class factory
  50. CMountedVolume* pMountedVolume = new CMountedVolume();
  51. if (pMountedVolume)
  52. {
  53. hr = pMountedVolume->QueryInterface(riid, ppv);
  54. pMountedVolume->Release();
  55. }
  56. return hr;
  57. }
  58. //IUnknown handling
  59. STDMETHODIMP CMountedVolume::QueryInterface(REFIID riid,void **ppvObj)
  60. {
  61. static const QITAB qit[] = {
  62. QITABENT(CMountedVolume, IDataObject),
  63. QITABENT(CMountedVolume, IMountedVolume),
  64. { 0 },
  65. };
  66. return QISearch(this, qit, riid, ppvObj);
  67. }
  68. STDMETHODIMP_(ULONG) CMountedVolume::AddRef()
  69. {
  70. return InterlockedIncrement(&_cRef);
  71. }
  72. STDMETHODIMP_(ULONG) CMountedVolume::Release()
  73. {
  74. if (InterlockedDecrement(&_cRef))
  75. return _cRef;
  76. delete this;
  77. return 0;
  78. }
  79. //IDataObject handling
  80. STDMETHODIMP CMountedVolume::GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium)
  81. {
  82. HRESULT hr = E_FAIL;
  83. //make sure IMountedVolume::Initialize was called
  84. if (TEXT('\0') != _szMountPoint[0])
  85. {
  86. pmedium->hGlobal = NULL;
  87. pmedium->pUnkForRelease = NULL;
  88. pmedium->tymed = TYMED_HGLOBAL;
  89. if ((g_cfMountedVolume == pformatetcIn->cfFormat) && (TYMED_HGLOBAL & pformatetcIn->tymed))
  90. {
  91. pmedium->hGlobal = GlobalAlloc(GPTR, (MAX_PATH + 1) * SIZEOF(TCHAR) + SIZEOF(DROPFILES));
  92. if (pmedium->hGlobal)
  93. {
  94. LPDROPFILES pdf = (LPDROPFILES)pmedium->hGlobal;
  95. LPTSTR pszMountPoint = (LPTSTR)(pdf + 1);
  96. pdf->pFiles = SIZEOF(DROPFILES);
  97. ASSERT(pdf->pt.x==0);
  98. ASSERT(pdf->pt.y==0);
  99. ASSERT(pdf->fNC==FALSE);
  100. ASSERT(pdf->fWide==FALSE);
  101. #ifdef UNICODE
  102. pdf->fWide = TRUE;
  103. #endif
  104. //do the copy
  105. lstrcpy(pszMountPoint, _szMountPoint);
  106. hr = S_OK; // success
  107. }
  108. else
  109. hr = E_OUTOFMEMORY;
  110. }
  111. }
  112. else
  113. ASSERTMSG(0, "IMountedVolume::Initialize was NOT called prior to IMountedVolume::GetData");
  114. return hr;
  115. }
  116. STDMETHODIMP CMountedVolume::QueryGetData(LPFORMATETC pformatetcIn)
  117. {
  118. HRESULT hr = S_FALSE;
  119. if ((g_cfMountedVolume == pformatetcIn->cfFormat) && (TYMED_HGLOBAL & pformatetcIn->tymed))
  120. hr = S_OK;
  121. return hr;
  122. }
  123. STDMETHODIMP CMountedVolume::SetData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
  124. {
  125. return E_NOTIMPL;
  126. }
  127. STDMETHODIMP CMountedVolume::GetDataHere(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium )
  128. {
  129. return E_NOTIMPL;
  130. }
  131. STDMETHODIMP CMountedVolume::GetCanonicalFormatEtc(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut)
  132. {
  133. return E_NOTIMPL;
  134. }
  135. STDMETHODIMP CMountedVolume::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppenumFormatEtc)
  136. {
  137. return S_FALSE;
  138. }
  139. STDMETHODIMP CMountedVolume::DAdvise(FORMATETC *pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD *pdwConnection)
  140. {
  141. return OLE_E_ADVISENOTSUPPORTED;
  142. }
  143. STDMETHODIMP CMountedVolume::DUnadvise(DWORD dwConnection)
  144. {
  145. return OLE_E_ADVISENOTSUPPORTED;
  146. }
  147. STDMETHODIMP CMountedVolume::EnumDAdvise(LPENUMSTATDATA *ppenumAdvise)
  148. {
  149. return OLE_E_ADVISENOTSUPPORTED;
  150. }
  151. // IMountedVolume methods
  152. STDMETHODIMP CMountedVolume::Initialize(LPCWSTR pcszMountPoint)
  153. {
  154. lstrcpy(_szMountPoint, pcszMountPoint);
  155. PathAddBackslash(_szMountPoint);
  156. return S_OK;
  157. }