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.

95 lines
2.4 KiB

  1. //=============================================================================
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft
  4. // documentation.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  7. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  8. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  9. // PURPOSE.
  10. //
  11. // Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  12. //=============================================================================
  13. #include "stdafx.h"
  14. #include "globals.h"
  15. //
  16. // Global functions for extracting information from a primary's data object
  17. //
  18. HRESULT ExtractData(
  19. IDataObject* piDataObject,
  20. CLIPFORMAT cfClipFormat,
  21. BYTE* pbData,
  22. DWORD cbData
  23. )
  24. {
  25. if ( piDataObject == NULL )
  26. {
  27. return E_INVALIDARG;
  28. }
  29. HRESULT hr = S_OK;
  30. FORMATETC formatetc =
  31. {
  32. cfClipFormat,
  33. NULL,
  34. DVASPECT_CONTENT,
  35. -1,
  36. TYMED_HGLOBAL
  37. };
  38. STGMEDIUM stgmedium =
  39. {
  40. TYMED_HGLOBAL,
  41. NULL
  42. };
  43. do // false loop
  44. {
  45. stgmedium.hGlobal = ::GlobalAlloc(GPTR, cbData);
  46. if ( NULL == stgmedium.hGlobal )
  47. {
  48. hr = E_OUTOFMEMORY;
  49. break;
  50. }
  51. hr = piDataObject->GetDataHere( &formatetc, &stgmedium );
  52. if ( FAILED(hr) )
  53. {
  54. break;
  55. }
  56. BYTE* pbNewData = (BYTE*)::GlobalLock(stgmedium.hGlobal);
  57. if (NULL == pbNewData)
  58. {
  59. hr = E_UNEXPECTED;
  60. break;
  61. }
  62. ::memcpy( pbData, pbNewData, cbData );
  63. ::GlobalUnlock( stgmedium.hGlobal);
  64. } while (FALSE); // false loop
  65. if (NULL != stgmedium.hGlobal)
  66. {
  67. ::GlobalFree( stgmedium.hGlobal );
  68. }
  69. return hr;
  70. } // ExtractData()
  71. HRESULT ExtractString(
  72. IDataObject* piDataObject,
  73. CLIPFORMAT cfClipFormat,
  74. WCHAR* pstr,
  75. DWORD cchMaxLength)
  76. {
  77. return ExtractData( piDataObject, cfClipFormat,
  78. (PBYTE)pstr, cchMaxLength );
  79. }