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.

140 lines
4.0 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. ULONG __RPC_USER LPITEMIDLIST_UserSize64(ULONG *pFlags, ULONG StartingSize, LPITEMIDLIST *ppidl) {
  38. return StartingSize + sizeof(ULONG) + MyILSize(*ppidl);
  39. }
  40. UCHAR * __RPC_USER LPITEMIDLIST_UserMarshal(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl)
  41. {
  42. ULONG cb = MyILSize(*ppidl);
  43. // set the size of the BYTE_BLOB
  44. *((ULONG UNALIGNED *)pBuffer) = cb;
  45. pBuffer += sizeof(ULONG);
  46. if (cb)
  47. {
  48. // copy the pidl over
  49. memcpy(pBuffer, *ppidl, cb);
  50. }
  51. return pBuffer + cb;
  52. }
  53. UCHAR * __RPC_USER LPITEMIDLIST_UserMarshal64(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl) {
  54. return LPITEMIDLIST_UserMarshal(pFlags, pBuffer, ppidl);
  55. }
  56. UCHAR * __RPC_USER LPITEMIDLIST_UserUnmarshal(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl)
  57. {
  58. ULONG cb = *((ULONG UNALIGNED *)pBuffer);
  59. pBuffer += sizeof(ULONG);
  60. if (cb)
  61. {
  62. //ASSERT(cb == MyILSize((LPCITEMIDLIST)pBuffer);
  63. *ppidl = (LPITEMIDLIST)CoTaskMemRealloc(*ppidl, cb);
  64. if (*ppidl)
  65. {
  66. memcpy(*ppidl, pBuffer, cb);
  67. }
  68. else
  69. {
  70. RpcRaiseException(E_OUTOFMEMORY);
  71. }
  72. }
  73. else
  74. *ppidl = NULL;
  75. return pBuffer + cb;
  76. }
  77. UCHAR * __RPC_USER LPITEMIDLIST_UserUnmarshal64(ULONG *pFlags, UCHAR *pBuffer, LPITEMIDLIST *ppidl) {
  78. return LPITEMIDLIST_UserUnmarshal(pFlags, pBuffer, ppidl);
  79. }
  80. void __RPC_USER LPITEMIDLIST_UserFree(ULONG *pFlags, LPITEMIDLIST *ppidl)
  81. {
  82. CoTaskMemFree(*ppidl);
  83. }
  84. void __RPC_USER LPITEMIDLIST_UserFree64(ULONG *pFlags, LPITEMIDLIST *ppidl) {
  85. CoTaskMemFree(*ppidl);
  86. }
  87. ULONG __RPC_USER LPCITEMIDLIST_UserSize(ULONG *pFlags, ULONG StartingSize, LPCITEMIDLIST *ppidl)
  88. {
  89. return LPITEMIDLIST_UserSize(pFlags, StartingSize, (LPITEMIDLIST *)ppidl);
  90. }
  91. ULONG __RPC_USER LPCITEMIDLIST_UserSize64(ULONG *pFlags, ULONG StartingSize, LPCITEMIDLIST *ppidl) {
  92. return LPITEMIDLIST_UserSize(pFlags, StartingSize, (LPITEMIDLIST *)ppidl);
  93. }
  94. UCHAR * __RPC_USER LPCITEMIDLIST_UserMarshal(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl)
  95. {
  96. return LPITEMIDLIST_UserMarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  97. }
  98. UCHAR * __RPC_USER LPCITEMIDLIST_UserMarshal64(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl) {
  99. return LPITEMIDLIST_UserMarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  100. }
  101. UCHAR * __RPC_USER LPCITEMIDLIST_UserUnmarshal(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl)
  102. {
  103. return LPITEMIDLIST_UserUnmarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  104. }
  105. UCHAR * __RPC_USER LPCITEMIDLIST_UserUnmarshal64(ULONG *pFlags, UCHAR *pBuffer, LPCITEMIDLIST *ppidl)
  106. {
  107. return LPITEMIDLIST_UserUnmarshal(pFlags, pBuffer, (LPITEMIDLIST *)ppidl);
  108. }
  109. void __RPC_USER LPCITEMIDLIST_UserFree(ULONG *pFlags, LPCITEMIDLIST *ppidl)
  110. {
  111. CoTaskMemFree((LPITEMIDLIST)*ppidl);
  112. }
  113. void __RPC_USER LPCITEMIDLIST_UserFree64(ULONG *pFlags, LPCITEMIDLIST *ppidl) {
  114. CoTaskMemFree((LPITEMIDLIST)*ppidl);
  115. }