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.

109 lines
2.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //
  6. // File: wire_mar.c
  7. //
  8. // Contents: wire_marshal routines for shell data types
  9. //
  10. // History: 18-JUN-99 ZekeL - created file
  11. //
  12. //--------------------------------------------------------------------------
  13. #define DUMMYUNIONNAME
  14. #include <shtypes.h>
  15. #include <ole2.h>
  16. // unsafe macros
  17. #define _ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))
  18. #define _ILNext(pidl) _ILSkip(pidl, (pidl)->mkid.cb)
  19. ULONG MyILSize(LPCITEMIDLIST pidl)
  20. {
  21. ULONG cb = 0;
  22. if (pidl)
  23. {
  24. cb = sizeof(pidl->mkid.cb); // Null terminator
  25. while (pidl->mkid.cb)
  26. {
  27. cb += pidl->mkid.cb;
  28. pidl = _ILNext(pidl);
  29. }
  30. }
  31. return cb;
  32. }
  33. ULONG __RPC_USER LPITEMIDLIST_UserSize(ULONG *pFlags, ULONG StartingSize, LPITEMIDLIST *ppidl)
  34. {
  35. return StartingSize + sizeof(ULONG) + MyILSize(*ppidl);
  36. }
  37. UCHAR * __RPC_USER LPITEMIDLIST_UserMarshal(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl)
  38. {
  39. ULONG cb = MyILSize(*ppidl);
  40. // set the size of the BYTE_BLOB
  41. *((ULONG UNALIGNED *)pBuffer) = cb;
  42. pBuffer += sizeof(ULONG);
  43. if (cb)
  44. {
  45. // copy the pidl over
  46. memcpy(pBuffer, *ppidl, cb);
  47. }
  48. return pBuffer + cb;
  49. }
  50. UCHAR * __RPC_USER LPITEMIDLIST_UserUnmarshal(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl)
  51. {
  52. ULONG cb = *((ULONG UNALIGNED *)pBuffer);
  53. pBuffer += sizeof(ULONG);
  54. if (cb)
  55. {
  56. //ASSERT(cb == MyILSize((LPCITEMIDLIST)pBuffer);
  57. *ppidl = (LPITEMIDLIST)CoTaskMemRealloc(*ppidl, cb);
  58. if (*ppidl)
  59. {
  60. memcpy(*ppidl, pBuffer, cb);
  61. }
  62. else
  63. {
  64. RpcRaiseException(E_OUTOFMEMORY);
  65. }
  66. }
  67. else
  68. *ppidl = NULL;
  69. return pBuffer + cb;
  70. }
  71. void __RPC_USER LPITEMIDLIST_UserFree(ULONG *pFlags, LPITEMIDLIST *ppidl)
  72. {
  73. CoTaskMemFree(*ppidl);
  74. }
  75. ULONG __RPC_USER LPCITEMIDLIST_UserSize(ULONG *pFlags, ULONG StartingSize, LPCITEMIDLIST *ppidl)
  76. {
  77. return LPITEMIDLIST_UserSize(pFlags, StartingSize, (LPITEMIDLIST *)ppidl);
  78. }
  79. UCHAR * __RPC_USER LPCITEMIDLIST_UserMarshal(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl)
  80. {
  81. return LPITEMIDLIST_UserMarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  82. }
  83. UCHAR * __RPC_USER LPCITEMIDLIST_UserUnmarshal(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl)
  84. {
  85. return LPITEMIDLIST_UserUnmarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  86. }
  87. void __RPC_USER LPCITEMIDLIST_UserFree(ULONG *pFlags, LPCITEMIDLIST *ppidl)
  88. {
  89. CoTaskMemFree((LPITEMIDLIST)*ppidl);
  90. }