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.

119 lines
2.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: dutil.cxx
  7. //
  8. // Contents: Utility functions and macros for data objects
  9. //
  10. // History: 14-Dec-95 BruceFo Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include "dutil.hxx"
  16. LPIDA
  17. DataObj_GetHIDA(
  18. LPDATAOBJECT pdtobj,
  19. STGMEDIUM* pmedium
  20. )
  21. {
  22. FORMATETC fmte = {(CLIPFORMAT)g_cfHIDA, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  23. if (NULL != pmedium)
  24. {
  25. pmedium->pUnkForRelease = NULL;
  26. pmedium->hGlobal = NULL;
  27. }
  28. if (NULL == pmedium)
  29. {
  30. if (SUCCEEDED(pdtobj->QueryGetData(&fmte)))
  31. {
  32. return (LPIDA)TRUE;
  33. }
  34. else
  35. {
  36. return (LPIDA)FALSE;
  37. }
  38. }
  39. else if (SUCCEEDED(pdtobj->GetData(&fmte, pmedium)))
  40. {
  41. return (LPIDA)GlobalLock(pmedium->hGlobal);
  42. }
  43. return NULL;
  44. }
  45. VOID
  46. HIDA_ReleaseStgMedium(
  47. LPIDA pida,
  48. STGMEDIUM* pmedium
  49. )
  50. {
  51. if ((NULL != pmedium->hGlobal) && (pmedium->tymed==TYMED_HGLOBAL))
  52. {
  53. #if DBG == 1
  54. if (NULL != pida)
  55. {
  56. LPIDA pidaT = (LPIDA)GlobalLock(pmedium->hGlobal);
  57. appAssert(pidaT == pida);
  58. GlobalUnlock(pmedium->hGlobal);
  59. }
  60. #endif
  61. GlobalUnlock(pmedium->hGlobal);
  62. }
  63. else
  64. {
  65. appAssert(FALSE);
  66. }
  67. ReleaseStgMedium(pmedium);
  68. }
  69. LPITEMIDLIST*
  70. ILA_Clone(
  71. UINT cidl,
  72. LPCITEMIDLIST* apidl
  73. )
  74. {
  75. LPITEMIDLIST* aNewPidl = new LPITEMIDLIST[cidl];
  76. if (NULL == aNewPidl)
  77. {
  78. return NULL;
  79. }
  80. for (UINT i = 0; i < cidl; i++)
  81. {
  82. aNewPidl[i] = ILClone(apidl[i]);
  83. if (NULL == aNewPidl[i])
  84. {
  85. // delete what we've allocated so far
  86. for (UINT j = 0; j < i; j++)
  87. {
  88. ILFree(aNewPidl[i]);
  89. }
  90. delete[] aNewPidl;
  91. return NULL;
  92. }
  93. }
  94. return aNewPidl;
  95. }
  96. VOID
  97. ILA_Free(
  98. UINT cidl,
  99. LPITEMIDLIST* apidl
  100. )
  101. {
  102. for (UINT i = 0; i < cidl; i++)
  103. {
  104. ILFree(apidl[i]);
  105. }
  106. delete[] apidl;
  107. }