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.

228 lines
6.6 KiB

  1. //+============================================================================
  2. //
  3. // propfwd.cxx
  4. //
  5. // This file provides (slow) forwarders of the NT4 property APIs
  6. // from NTDLL to OLE32. At one time, these APIs were used in both
  7. // kernel mode and user mode. They're now only used in user mode,
  8. // so all the property code has been consolidated into ole32. Older
  9. // copies of Index Server (CI), however, still link to NTDLL, thus
  10. // the need for these forwarders.
  11. //
  12. //+============================================================================
  13. #include <pch.cxx>
  14. #include <windows.h>
  15. #include <ddeml.h> // for CP_WINUNICODE
  16. #include <objidl.h>
  17. #include <propidl.h>
  18. extern "C"
  19. {
  20. #include <propapi.h>
  21. }
  22. #include <stgprop.h>
  23. class PMemoryAllocator;
  24. #include <propstm.hxx>
  25. #include <align.hxx>
  26. #include <sstream.hxx>
  27. #include "propmac.hxx"
  28. //+----------------------------------------------------------------------------
  29. //
  30. // Function: LoadOle32Export
  31. //
  32. // Synopsis: Load ole32.dll and get one of its exports.
  33. // Raises on error.
  34. //
  35. //+----------------------------------------------------------------------------
  36. PVOID
  37. LoadOle32Export( PVOID* Ole32, const PCHAR ProcedureName )
  38. {
  39. NTSTATUS Status;
  40. const static UNICODE_STRING Ole32DllName_U = RTL_CONSTANT_STRING(L"ole32.dll");
  41. STRING ProcedureNameString;
  42. PVOID ProcedureAddress = NULL;
  43. Status = LdrLoadDll( NULL, NULL, &Ole32DllName_U, Ole32 );
  44. if( !NT_SUCCESS(Status) )
  45. RtlRaiseStatus( Status );
  46. RtlInitString( &ProcedureNameString, ProcedureName );
  47. Status = LdrGetProcedureAddress(
  48. *Ole32,
  49. &ProcedureNameString,
  50. 0,
  51. (PVOID*) &ProcedureAddress
  52. );
  53. if( !NT_SUCCESS(Status) )
  54. RtlRaiseStatus(Status);
  55. return( ProcedureAddress );
  56. }
  57. //+----------------------------------------------------------------------------
  58. //
  59. // Function: RtlConvertVariantToProperty
  60. //
  61. // Synopsis: Serialize a variant.
  62. //
  63. //+----------------------------------------------------------------------------
  64. typedef SERIALIZEDPROPERTYVALUE* (*PFNStgConvertVariantToProperty) (
  65. IN PROPVARIANT const *pvar,
  66. IN USHORT CodePage,
  67. OUT SERIALIZEDPROPERTYVALUE *pprop,
  68. IN OUT ULONG *pcb,
  69. IN PROPID pid,
  70. IN BOOLEAN fVariantVector,
  71. OPTIONAL OUT ULONG *pcIndirect);
  72. SERIALIZEDPROPERTYVALUE * PROPSYSAPI PROPAPI
  73. RtlConvertVariantToProperty(
  74. IN PROPVARIANT const *pvar,
  75. IN USHORT CodePage,
  76. OPTIONAL OUT SERIALIZEDPROPERTYVALUE *pprop,
  77. IN OUT ULONG *pcb,
  78. IN PROPID pid,
  79. IN BOOLEAN fVariantVector,
  80. OPTIONAL OUT ULONG *pcIndirect)
  81. {
  82. PVOID Ole32 = NULL;
  83. PFNStgConvertVariantToProperty ProcedureAddress;
  84. SERIALIZEDPROPERTYVALUE *ppropRet = NULL;
  85. __try
  86. {
  87. ProcedureAddress = (PFNStgConvertVariantToProperty)
  88. LoadOle32Export( &Ole32, "StgConvertVariantToProperty" );
  89. ppropRet = ProcedureAddress( pvar,
  90. CodePage,
  91. pprop,
  92. pcb,
  93. pid,
  94. fVariantVector,
  95. pcIndirect ); // Raises on error
  96. }
  97. __finally
  98. {
  99. if( NULL != Ole32 )
  100. LdrUnloadDll( Ole32 );
  101. }
  102. return (ppropRet );
  103. }
  104. //+----------------------------------------------------------------------------
  105. //
  106. // Function: RtlConvertPropertyToVariant
  107. //
  108. // Synopsis: De-serialize a variant.
  109. //
  110. //+----------------------------------------------------------------------------
  111. typedef BOOLEAN (* PFNStgConvertPropertyToVariant) (
  112. IN SERIALIZEDPROPERTYVALUE const *pprop,
  113. IN USHORT CodePage,
  114. OUT PROPVARIANT *pvar,
  115. IN PMemoryAllocator *pma);
  116. BOOLEAN PROPSYSAPI PROPAPI
  117. RtlConvertPropertyToVariant(
  118. IN SERIALIZEDPROPERTYVALUE const *pprop,
  119. IN USHORT CodePage,
  120. OUT PROPVARIANT *pvar,
  121. IN PMemoryAllocator *pma)
  122. {
  123. BOOLEAN Ret = FALSE;
  124. PVOID Ole32 = NULL;
  125. PFNStgConvertPropertyToVariant ProcedureAddress;
  126. __try
  127. {
  128. ProcedureAddress = (PFNStgConvertPropertyToVariant)
  129. LoadOle32Export( &Ole32, "StgConvertPropertyToVariant" );
  130. Ret = ProcedureAddress( pprop, CodePage, pvar, pma ); // Raises on error
  131. }
  132. __finally
  133. {
  134. if( NULL != Ole32 )
  135. LdrUnloadDll( Ole32 );
  136. }
  137. return (Ret);
  138. }
  139. //+----------------------------------------------------------------------------
  140. //
  141. // Function: PropertyLengthAsVariant
  142. //
  143. // Synopsis: Returns the amount of external memory will need to be
  144. // allocated for this variant when RtlPropertyToVariant is called.
  145. //
  146. //+----------------------------------------------------------------------------
  147. typedef ULONG (*PFNStgPropertyLengthAsVariant)(
  148. IN SERIALIZEDPROPERTYVALUE const *pprop,
  149. IN ULONG cbprop,
  150. IN USHORT CodePage,
  151. IN BYTE flags);
  152. ULONG PROPSYSAPI PROPAPI
  153. PropertyLengthAsVariant(
  154. IN SERIALIZEDPROPERTYVALUE const *pprop,
  155. IN ULONG cbprop,
  156. IN USHORT CodePage,
  157. IN BYTE flags)
  158. {
  159. ULONG Length = 0;
  160. PVOID Ole32 = NULL;
  161. PFNStgPropertyLengthAsVariant ProcedureAddress;
  162. __try
  163. {
  164. ProcedureAddress = (PFNStgPropertyLengthAsVariant)
  165. LoadOle32Export( &Ole32, "StgPropertyLengthAsVariant" );
  166. Length = ProcedureAddress( pprop, cbprop, CodePage, flags ); // Raises on error
  167. }
  168. __finally
  169. {
  170. if( NULL != Ole32 )
  171. LdrUnloadDll( Ole32 );
  172. }
  173. return( Length);
  174. }
  175. //+---------------------------------------------------------------------------
  176. //
  177. // Function: RtlSetUnicodeCallouts, public
  178. //
  179. // Synopsis: Set the Unicode conversion function pointers, used by
  180. // RtlConvertVarianttoProperty, RtlConvertPropertyToVariant,
  181. // and PropertyLengthAsVariant.
  182. //
  183. // These functions are no longer settable (they're defaulted by
  184. // ole32).
  185. //
  186. //---------------------------------------------------------------------------
  187. VOID PROPSYSAPI PROPAPI
  188. RtlSetUnicodeCallouts(
  189. IN UNICODECALLOUTS *pUnicodeCallouts)
  190. {
  191. return;
  192. }