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.

89 lines
2.1 KiB

  1. // DataObj.cpp : Implementation of CBOMSnapApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "BOMSnap.h"
  4. #include "DataObj.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. HRESULT CDataObjectImpl::GetData(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium)
  8. {
  9. if( !lpFormatetcIn || !lpMedium ) return E_POINTER;
  10. if (lpFormatetcIn->dwAspect != DVASPECT_CONTENT ||
  11. (lpFormatetcIn->tymed & TYMED_HGLOBAL) == 0)
  12. return DV_E_FORMATETC;
  13. HGLOBAL hGlobal = NULL;
  14. HRESULT hr = GetDataImpl(lpFormatetcIn->cfFormat, &hGlobal);
  15. RETURN_ON_FAILURE(hr);
  16. ASSERT(hGlobal != NULL);
  17. lpMedium->tymed = TYMED_HGLOBAL;
  18. lpMedium->hGlobal = hGlobal;
  19. lpMedium->pUnkForRelease = NULL;
  20. return S_OK;
  21. }
  22. HRESULT CDataObjectImpl::GetDataHere(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium)
  23. {
  24. if( !lpFormatetcIn || !lpMedium ) return E_POINTER;
  25. if (lpFormatetcIn->dwAspect != DVASPECT_CONTENT || (lpFormatetcIn->tymed != TYMED_HGLOBAL))
  26. {
  27. return DV_E_FORMATETC;
  28. }
  29. if (lpMedium->tymed != TYMED_HGLOBAL || lpMedium->hGlobal == NULL )
  30. {
  31. return E_INVALIDARG;
  32. }
  33. return GetDataImpl(lpFormatetcIn->cfFormat, &lpMedium->hGlobal);
  34. }
  35. HRESULT CDataObjectImpl::DataToGlobal(HGLOBAL* phGlobal, const void* pData, DWORD dwSize)
  36. {
  37. if( !phGlobal || !pData ) return E_POINTER;
  38. HRESULT hr = S_OK;
  39. HGLOBAL hGlobal = *phGlobal;
  40. if (hGlobal)
  41. {
  42. if (GlobalSize(hGlobal) < dwSize)
  43. {
  44. hr = STG_E_MEDIUMFULL;
  45. }
  46. }
  47. else
  48. {
  49. hGlobal = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, dwSize);
  50. if (hGlobal != NULL)
  51. {
  52. *phGlobal = hGlobal;
  53. }
  54. else
  55. {
  56. hr = STG_E_MEDIUMFULL;
  57. }
  58. }
  59. if (SUCCEEDED(hr))
  60. {
  61. void* pMem = GlobalLock(hGlobal);
  62. if( !pMem ) return E_OUTOFMEMORY;
  63. memcpy(pMem, pData, dwSize);
  64. GlobalUnlock(hGlobal);
  65. }
  66. return hr;
  67. }