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.

205 lines
5.5 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. ASSERT( 0 != _cRef );
  75. ULONG cRef = InterlockedDecrement(&_cRef);
  76. if ( 0 == cRef )
  77. {
  78. delete this;
  79. }
  80. return cRef;
  81. }
  82. #define GETDATA_BUFSIZE MAX_PATH
  83. //IDataObject handling
  84. STDMETHODIMP CMountedVolume::GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium)
  85. {
  86. HRESULT hr = E_FAIL;
  87. //make sure IMountedVolume::Initialize was called
  88. if (TEXT('\0') != _szMountPoint[0])
  89. {
  90. pmedium->hGlobal = NULL;
  91. pmedium->pUnkForRelease = NULL;
  92. pmedium->tymed = TYMED_HGLOBAL;
  93. if ((g_cfMountedVolume == pformatetcIn->cfFormat) && (TYMED_HGLOBAL & pformatetcIn->tymed))
  94. {
  95. pmedium->hGlobal = GlobalAlloc(GPTR, (GETDATA_BUFSIZE + 1) * SIZEOF(TCHAR) + SIZEOF(DROPFILES));
  96. if (pmedium->hGlobal)
  97. {
  98. LPDROPFILES pdf = (LPDROPFILES)pmedium->hGlobal;
  99. LPTSTR pszMountPoint = (LPTSTR)(pdf + 1);
  100. pdf->pFiles = SIZEOF(DROPFILES);
  101. ASSERT(pdf->pt.x==0);
  102. ASSERT(pdf->pt.y==0);
  103. ASSERT(pdf->fNC==FALSE);
  104. ASSERT(pdf->fWide==FALSE);
  105. #ifdef UNICODE
  106. pdf->fWide = TRUE;
  107. #endif
  108. //do the copy
  109. hr = StringCchCopy(pszMountPoint, GETDATA_BUFSIZE, _szMountPoint);
  110. }
  111. else
  112. hr = E_OUTOFMEMORY;
  113. }
  114. }
  115. else
  116. ASSERTMSG(0, "IMountedVolume::Initialize was NOT called prior to IMountedVolume::GetData");
  117. return hr;
  118. }
  119. STDMETHODIMP CMountedVolume::QueryGetData(LPFORMATETC pformatetcIn)
  120. {
  121. HRESULT hr = S_FALSE;
  122. if ((g_cfMountedVolume == pformatetcIn->cfFormat) && (TYMED_HGLOBAL & pformatetcIn->tymed))
  123. hr = S_OK;
  124. return hr;
  125. }
  126. STDMETHODIMP CMountedVolume::SetData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
  127. {
  128. return E_NOTIMPL;
  129. }
  130. STDMETHODIMP CMountedVolume::GetDataHere(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium )
  131. {
  132. return E_NOTIMPL;
  133. }
  134. STDMETHODIMP CMountedVolume::GetCanonicalFormatEtc(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut)
  135. {
  136. return E_NOTIMPL;
  137. }
  138. STDMETHODIMP CMountedVolume::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppenumFormatEtc)
  139. {
  140. return S_FALSE;
  141. }
  142. STDMETHODIMP CMountedVolume::DAdvise(FORMATETC *pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD *pdwConnection)
  143. {
  144. return OLE_E_ADVISENOTSUPPORTED;
  145. }
  146. STDMETHODIMP CMountedVolume::DUnadvise(DWORD dwConnection)
  147. {
  148. return OLE_E_ADVISENOTSUPPORTED;
  149. }
  150. STDMETHODIMP CMountedVolume::EnumDAdvise(LPENUMSTATDATA *ppenumAdvise)
  151. {
  152. return OLE_E_ADVISENOTSUPPORTED;
  153. }
  154. // IMountedVolume methods
  155. STDMETHODIMP CMountedVolume::Initialize(LPCWSTR pcszMountPoint)
  156. {
  157. HRESULT hr;
  158. if (SUCCEEDED(StringCchCopy(_szMountPoint, ARRAYSIZE(_szMountPoint), pcszMountPoint)) &&
  159. PathAddBackslash(_szMountPoint))
  160. {
  161. hr = S_OK;
  162. }
  163. else
  164. {
  165. hr = E_FAIL;
  166. }
  167. return hr;
  168. }