[LWIP] Fix src/core/init.c a bit (#1620)
[reactos.git] / sdk / lib / rtl / propvar.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/rtl/propvar.c
5 * PURPOSE: Native properties and variants API
6 * PROGRAMMER: Pierre Schweitzer (pierre@reactos.org)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <rtl.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ***************************************************************/
17
18 UNICODE_STRING Old32Dll = RTL_CONSTANT_STRING(L"ole32.dll");
19 /* FIXME: (or not)
20 * Define those here to allow build. They don't need to be dereferenced
21 * so it's OK.
22 * Furthermore till Vista those Ole32 API were private so those defines
23 * should be made in a private header
24 * Finally, having those defined that way allows to write that code plain C.
25 */
26 typedef PVOID PPMemoryAllocator;
27 typedef PVOID PSERIALIZEDPROPERTYVALUE;
28
29 /*
30 * @implemented
31 */
32 PVOID
33 LoadOle32Export(PVOID * BaseAddress, const PCHAR ProcedureName)
34 {
35 NTSTATUS Status;
36 ANSI_STRING ExportName;
37 PVOID ProcedureAddress;
38
39 /* First load ole32.dll */
40 Status = LdrLoadDll(NULL, NULL, &Old32Dll, BaseAddress);
41 if (!NT_SUCCESS(Status))
42 {
43 RtlRaiseStatus(Status);
44 }
45
46 RtlInitAnsiString(&ExportName, ProcedureName);
47
48 /* Look for the procedure */
49 Status = LdrGetProcedureAddress(*BaseAddress, &ExportName,
50 0, &ProcedureAddress);
51 if (!NT_SUCCESS(Status))
52 {
53 RtlRaiseStatus(Status);
54 }
55
56 /* Return its address */
57 return ProcedureAddress;
58 }
59
60 /*
61 * @implemented
62 */
63 ULONG
64 NTAPI
65 PropertyLengthAsVariant(IN PSERIALIZEDPROPERTYVALUE pProp,
66 IN ULONG cbProp,
67 IN USHORT CodePage,
68 IN BYTE bReserved)
69 {
70 ULONG Length = 0;
71 PVOID BaseAddress = NULL;
72 ULONG (*ProcedureAddress)(PSERIALIZEDPROPERTYVALUE, ULONG, USHORT, BYTE);
73
74 _SEH2_TRY
75 {
76 /* Simply call the appropriate Ole32 export */
77 ProcedureAddress = LoadOle32Export(&BaseAddress,
78 "StgPropertyLengthAsVariant");
79
80 Length = ProcedureAddress(pProp, cbProp, CodePage, bReserved);
81 }
82 _SEH2_FINALLY
83 {
84 if (BaseAddress != NULL)
85 {
86 LdrUnloadDll(BaseAddress);
87 }
88 }
89 _SEH2_END;
90
91 return Length;
92 }
93
94 /*
95 * @implemented
96 */
97 BOOLEAN
98 NTAPI
99 RtlConvertPropertyToVariant(IN PSERIALIZEDPROPERTYVALUE prop,
100 IN USHORT CodePage,
101 OUT PROPVARIANT * pvar,
102 IN PPMemoryAllocator pma)
103 {
104 BOOLEAN Success = FALSE;
105 PVOID BaseAddress = NULL;
106 BOOLEAN (*ProcedureAddress)(PSERIALIZEDPROPERTYVALUE, USHORT, PROPVARIANT*, PPMemoryAllocator);
107
108 _SEH2_TRY
109 {
110 /* Simply call the appropriate Ole32 export */
111 ProcedureAddress = LoadOle32Export(&BaseAddress,
112 "StgConvertPropertyToVariant");
113
114 Success = ProcedureAddress(prop, CodePage, pvar, pma);
115 }
116 _SEH2_FINALLY
117 {
118 if (BaseAddress != NULL)
119 {
120 LdrUnloadDll(BaseAddress);
121 }
122 }
123 _SEH2_END;
124
125 return Success;
126 }
127
128 /*
129 * @implemented
130 */
131 PSERIALIZEDPROPERTYVALUE
132 NTAPI
133 RtlConvertVariantToProperty(IN const PROPVARIANT * pvar,
134 IN USHORT CodePage,
135 OUT PSERIALIZEDPROPERTYVALUE pprop OPTIONAL,
136 IN OUT PULONG pcb,
137 IN PROPID pid,
138 IN BOOLEAN fReserved,
139 IN OUT PULONG pcIndirect OPTIONAL)
140 {
141 PSERIALIZEDPROPERTYVALUE Serialized = NULL;
142 PVOID BaseAddress = NULL;
143 PSERIALIZEDPROPERTYVALUE (*ProcedureAddress)(const PROPVARIANT*, USHORT, PSERIALIZEDPROPERTYVALUE,
144 PULONG, PROPID, BOOLEAN, PULONG);
145
146 _SEH2_TRY
147 {
148 /* Simply call the appropriate Ole32 export */
149 ProcedureAddress = LoadOle32Export(&BaseAddress,
150 "StgConvertVariantToProperty");
151
152 Serialized = ProcedureAddress(pvar, CodePage, pprop, pcb, pid, fReserved, pcIndirect);
153 }
154 _SEH2_FINALLY
155 {
156 if (BaseAddress != NULL)
157 {
158 LdrUnloadDll(BaseAddress);
159 }
160 }
161 _SEH2_END;
162
163 return Serialized;
164 }
165
166
167 /* EOF */