Get rid of the WIN_SetRectangles export from user32.
[wine.git] / dlls / oleaut32 / variant.h
blob237687a32093c05ad92d552a9f5d32e8b379a922
1 /*
2 * Variant Inlines
4 * Copyright 2003 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22 #include "windef.h"
23 #include "winerror.h"
24 #include "objbase.h"
25 #include "oleauto.h"
26 #include <math.h>
28 /* Get just the type from a variant pointer */
29 #define V_TYPE(v) (V_VT((v)) & VT_TYPEMASK)
31 /* Flags set in V_VT, other than the actual type value */
32 #define VT_EXTRA_TYPE (VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED)
34 /* Get the extra flags from a variant pointer */
35 #define V_EXTRA_TYPE(v) (V_VT((v)) & VT_EXTRA_TYPE)
37 extern const char* wine_vtypes[];
38 #define debugstr_vt(v) (((v)&VT_TYPEMASK) <= VT_CLSID ? wine_vtypes[((v)&VT_TYPEMASK)] : \
39 ((v)&VT_TYPEMASK) == VT_BSTR_BLOB ? "VT_BSTR_BLOB": "Invalid")
40 #define debugstr_VT(v) (!(v) ? "(null)" : debugstr_vt(V_TYPE((v))))
42 extern const char* wine_vflags[];
43 #define debugstr_vf(v) (wine_vflags[((v)&VT_EXTRA_TYPE)>>12])
44 #define debugstr_VF(v) (!(v) ? "(null)" : debugstr_vf(V_EXTRA_TYPE(v)))
46 /* Size constraints */
47 #define I1_MAX 0x7f
48 #define I1_MIN ((-I1_MAX)-1)
49 #define UI1_MAX 0xff
50 #define UI1_MIN 0
51 #define I2_MAX 0x7fff
52 #define I2_MIN ((-I2_MAX)-1)
53 #define UI2_MAX 0xffff
54 #define UI2_MIN 0
55 #define I4_MAX 0x7fffffff
56 #define I4_MIN ((-I4_MAX)-1)
57 #define UI4_MAX 0xffffffff
58 #define UI4_MIN 0
59 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
60 #define I8_MIN ((-I8_MAX)-1)
61 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
62 #define UI8_MIN 0
63 #define DATE_MAX 2958465
64 #define DATE_MIN -657434
65 #define R4_MAX 3.402823567797336e38
66 #define R4_MIN 1.40129846432481707e-45
67 #define R8_MAX 1.79769313486231470e+308
68 #define R8_MIN 4.94065645841246544e-324
70 /* Value of sign for a positive decimal number */
71 #define DECIMAL_POS 0
73 /* Native headers don't change the union ordering for DECIMAL sign/scale (duh).
74 * This means that the signscale member is only useful for setting both members to 0.
75 * SIGNSCALE creates endian-correct values so that we can properly set both at once
76 * to values other than 0.
78 #ifdef WORDS_BIGENDIAN
79 #define SIGNSCALE(sign,scale) (((scale) << 8) | sign)
80 #else
81 #define SIGNSCALE(sign,scale) (((sign) << 8) | scale)
82 #endif
84 /* Macros for getting at a DECIMAL's parts */
85 #define DEC_SIGN(d) ((d)->u.s.sign)
86 #define DEC_SCALE(d) ((d)->u.s.scale)
87 #define DEC_SIGNSCALE(d) ((d)->u.signscale)
88 #define DEC_HI32(d) ((d)->Hi32)
89 #define DEC_MID32(d) ((d)->u1.s1.Mid32)
90 #define DEC_LO32(d) ((d)->u1.s1.Lo32)
91 #define DEC_LO64(d) ((d)->u1.Lo64)
93 #define DEC_MAX_SCALE 28 /* Maximum scale for a decimal */
95 /* Inline return type */
96 #define RETTYP inline static HRESULT
98 /* Simple compiler cast from one type to another */
99 #define SIMPLE(dest, src, func) RETTYP _##func(src in, dest* out) { \
100 *out = in; return S_OK; }
102 /* Compiler cast where input cannot be negative */
103 #define NEGTST(dest, src, func) RETTYP _##func(src in, dest* out) { \
104 if (in < (src)0) return DISP_E_OVERFLOW; *out = in; return S_OK; }
106 /* Compiler cast where input cannot be > some number */
107 #define POSTST(dest, src, func, tst) RETTYP _##func(src in, dest* out) { \
108 if (in > (dest)tst) return DISP_E_OVERFLOW; *out = in; return S_OK; }
110 /* Compiler cast where input cannot be < some number or >= some other number */
111 #define BOTHTST(dest, src, func, lo, hi) RETTYP _##func(src in, dest* out) { \
112 if (in < (dest)lo || in > hi) return DISP_E_OVERFLOW; *out = in; return S_OK; }
114 /* Conversions from IDispatch use the same code */
115 HRESULT VARIANT_FromDisp(IDispatch*,LCID,void*,VARTYPE);
116 /* As do conversions from BSTR to numeric types */
117 HRESULT VARIANT_NumberFromBstr(OLECHAR*,LCID,ULONG,void*,VARTYPE);
119 #define CY_MULTIPLIER 10000 /* 4 dp of precision */
120 #define CY_MULTIPLIER_F 10000.0
121 #define CY_HALF (CY_MULTIPLIER/2) /* 0.5 */
122 #define CY_HALF_F (CY_MULTIPLIER_F/2.0)
124 /* I1 */
125 POSTST(signed char, BYTE, VarI1FromUI1, I1_MAX);
126 BOTHTST(signed char, SHORT, VarI1FromI2, I1_MIN, I1_MAX);
127 BOTHTST(signed char, LONG, VarI1FromI4, I1_MIN, I1_MAX);
128 #define _VarI1FromR4(flt,out) VarI1FromR8((double)flt,out)
129 #define _VarI1FromR8 VarI1FromR8
130 #define _VarI1FromCy VarI1FromCy
131 #define _VarI1FromDate(dt,out) VarI1FromR8((double)dt,out)
132 #define _VarI1FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_I1)
133 #define _VarI1FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, (BYTE*)out, VT_I1)
134 SIMPLE(signed char, VARIANT_BOOL, VarI1FromBool);
135 POSTST(signed char, USHORT, VarI1FromUI2, I1_MAX);
136 POSTST(signed char, ULONG, VarI1FromUI4, I1_MAX);
137 #define _VarI1FromDec VarI1FromDec
138 BOTHTST(signed char, LONG64, VarI1FromI8, I1_MIN, I1_MAX);
139 POSTST(signed char, ULONG64, VarI1FromUI8, I1_MAX);
141 /* UI1 */
142 BOTHTST(BYTE, SHORT, VarUI1FromI2, UI1_MIN, UI1_MAX);
143 #define _VarUI1FromR4(flt,out) VarUI1FromR8((double)flt,out)
144 #define _VarUI1FromR8 VarUI1FromR8
145 #define _VarUI1FromCy VarUI1FromCy
146 #define _VarUI1FromDate(dt,out) VarUI1FromR8((double)dt,out)
147 #define _VarUI1FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_UI1)
148 #define _VarUI1FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_UI1)
149 SIMPLE(BYTE, VARIANT_BOOL, VarUI1FromBool);
150 NEGTST(BYTE, signed char, VarUI1FromI1);
151 POSTST(BYTE, USHORT, VarUI1FromUI2, UI1_MAX);
152 BOTHTST(BYTE, LONG, VarUI1FromI4, UI1_MIN, UI1_MAX);
153 POSTST(BYTE, ULONG, VarUI1FromUI4, UI1_MAX);
154 #define _VarUI1FromDec VarUI1FromDec
155 BOTHTST(BYTE, LONG64, VarUI1FromI8, UI1_MIN, UI1_MAX);
156 POSTST(BYTE, ULONG64, VarUI1FromUI8, UI1_MAX);
158 /* I2 */
159 SIMPLE(SHORT, BYTE, VarI2FromUI1);
160 BOTHTST(SHORT, LONG, VarI2FromI4, I2_MIN, I2_MAX);
161 #define _VarI2FromR4(flt,out) VarI2FromR8((double)flt,out)
162 #define _VarI2FromR8 VarI2FromR8
163 #define _VarI2FromCy VarI2FromCy
164 #define _VarI2FromDate(dt,out) VarI2FromR8((double)dt,out)
165 #define _VarI2FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_I2)
166 #define _VarI2FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, (BYTE*)out, VT_I2)
167 SIMPLE(SHORT, VARIANT_BOOL, VarI2FromBool);
168 SIMPLE(SHORT, signed char, VarI2FromI1);
169 POSTST(SHORT, USHORT, VarI2FromUI2, I2_MAX);
170 POSTST(SHORT, ULONG, VarI2FromUI4, I2_MAX);
171 #define _VarI2FromDec VarI2FromDec
172 BOTHTST(SHORT, LONG64, VarI2FromI8, I2_MIN, I2_MAX);
173 POSTST(SHORT, ULONG64, VarI2FromUI8, I2_MAX);
175 /* UI2 */
176 SIMPLE(USHORT, BYTE, VarUI2FromUI1);
177 NEGTST(USHORT, SHORT, VarUI2FromI2);
178 BOTHTST(USHORT, LONG, VarUI2FromI4, UI2_MIN, UI2_MAX);
179 #define _VarUI2FromR4(flt,out) VarUI2FromR8((double)flt,out)
180 #define _VarUI2FromR8 VarUI2FromR8
181 #define _VarUI2FromCy VarUI2FromCy
182 #define _VarUI2FromDate(dt,out) VarUI2FromR8((double)dt,out)
183 #define _VarUI2FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_UI2)
184 #define _VarUI2FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_UI2)
185 SIMPLE(USHORT, VARIANT_BOOL, VarUI2FromBool);
186 NEGTST(USHORT, signed char, VarUI2FromI1);
187 POSTST(USHORT, ULONG, VarUI2FromUI4, UI2_MAX);
188 #define _VarUI2FromDec VarUI2FromDec
189 BOTHTST(USHORT, LONG64, VarUI2FromI8, UI2_MIN, UI2_MAX);
190 POSTST(USHORT, ULONG64, VarUI2FromUI8, UI2_MAX);
192 /* I4 */
193 SIMPLE(LONG, BYTE, VarI4FromUI1);
194 SIMPLE(LONG, SHORT, VarI4FromI2);
195 #define _VarI4FromR4(flt,out) VarI4FromR8((double)flt,out)
196 #define _VarI4FromR8 VarI4FromR8
197 #define _VarI4FromCy VarI4FromCy
198 #define _VarI4FromDate(dt,out) VarI4FromR8((double)dt,out)
199 #define _VarI4FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_I4)
200 #define _VarI4FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, (BYTE*)out, VT_I4)
201 SIMPLE(LONG, VARIANT_BOOL, VarI4FromBool);
202 SIMPLE(LONG, signed char, VarI4FromI1);
203 SIMPLE(LONG, USHORT, VarI4FromUI2);
204 POSTST(LONG, ULONG, VarI4FromUI4, I4_MAX);
205 #define _VarI4FromDec VarI4FromDec
206 BOTHTST(LONG, LONG64, VarI4FromI8, I4_MIN, I4_MAX);
207 POSTST(LONG, ULONG64, VarI4FromUI8, I4_MAX);
209 /* UI4 */
210 SIMPLE(ULONG, BYTE, VarUI4FromUI1);
211 NEGTST(ULONG, SHORT, VarUI4FromI2);
212 NEGTST(ULONG, LONG, VarUI4FromI4);
213 #define _VarUI4FromR4(flt,out) VarUI4FromR8((double)flt,out)
214 #define _VarUI4FromR8 VarUI4FromR8
215 #define _VarUI4FromCy VarUI4FromCy
216 #define _VarUI4FromDate(dt,out) VarUI4FromR8((double)dt,out)
217 #define _VarUI4FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_UI4)
218 #define _VarUI4FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_UI4)
219 SIMPLE(ULONG, VARIANT_BOOL, VarUI4FromBool);
220 NEGTST(ULONG, signed char, VarUI4FromI1);
221 SIMPLE(ULONG, USHORT, VarUI4FromUI2);
222 #define _VarUI4FromDec VarUI4FromDec
223 BOTHTST(ULONG, LONG64, VarUI4FromI8, UI4_MIN, UI4_MAX);
224 POSTST(ULONG, ULONG64, VarUI4FromUI8, UI4_MAX);
226 /* I8 */
227 SIMPLE(LONG64, BYTE, VarI8FromUI1);
228 SIMPLE(LONG64, SHORT, VarI8FromI2);
229 #define _VarI8FromR4 VarI8FromR8
230 #define _VarI8FromR8 VarI8FromR8
231 #define _VarI8FromCy VarI8FromCy
232 #define _VarI8FromDate(dt,out) VarI8FromR8((double)dt,out)
233 #define _VarI8FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_I8)
234 #define _VarI8FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_I8)
235 #define _VarI8FromBool _VarI8FromI2
236 SIMPLE(LONG64, signed char, VarI8FromI1);
237 SIMPLE(LONG64, USHORT, VarI8FromUI2);
238 SIMPLE(LONG64, LONG, VarI8FromI4);
239 SIMPLE(LONG64, ULONG, VarI8FromUI4);
240 #define _VarI8FromDec VarI8FromDec
241 POSTST(LONG64, ULONG64, VarI8FromUI8, I8_MAX);
243 /* UI8 */
244 SIMPLE(ULONG64, BYTE, VarUI8FromUI1);
245 NEGTST(ULONG64, SHORT, VarUI8FromI2);
246 #define _VarUI8FromR4 VarUI8FromR8
247 #define _VarUI8FromR8 VarUI8FromR8
248 #define _VarUI8FromCy VarUI8FromCy
249 #define _VarUI8FromDate(dt,out) VarUI8FromR8((double)dt,out)
250 #define _VarUI8FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_UI8)
251 #define _VarUI8FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_UI8)
252 #define _VarUI8FromBool _VarI8FromI2
253 NEGTST(ULONG64, signed char, VarUI8FromI1);
254 SIMPLE(ULONG64, USHORT, VarUI8FromUI2);
255 NEGTST(ULONG64, LONG, VarUI8FromI4);
256 SIMPLE(ULONG64, ULONG, VarUI8FromUI4);
257 #define _VarUI8FromDec VarUI8FromDec
258 NEGTST(ULONG64, LONG64, VarUI8FromI8);
260 /* R4 (float) */
261 SIMPLE(float, BYTE, VarR4FromUI1);
262 SIMPLE(float, SHORT, VarR4FromI2);
263 RETTYP _VarR4FromR8(double i, float* o) {
264 double d = i < 0.0 ? -i : i;
265 if (d > R4_MAX) return DISP_E_OVERFLOW;
266 *o = i;
267 return S_OK;
269 RETTYP _VarR4FromCy(CY i, float* o) { *o = (double)i.int64 / CY_MULTIPLIER_F; return S_OK; }
270 #define _VarR4FromDate(dt,out) _VarR4FromR8((double)dt,out)
271 #define _VarR4FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_R4)
272 #define _VarR4FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_R4)
273 #define _VarR4FromBool _VarR4FromI2
274 SIMPLE(float, signed char, VarR4FromI1);
275 SIMPLE(float, USHORT, VarR4FromUI2);
276 SIMPLE(float, LONG, VarR4FromI4);
277 SIMPLE(float, ULONG, VarR4FromUI4);
278 #define _VarR4FromDec VarR4FromDec
279 SIMPLE(float, LONG64, VarR4FromI8);
280 SIMPLE(float, ULONG64, VarR4FromUI8);
282 /* R8 (double) */
283 SIMPLE(double, BYTE, VarR8FromUI1);
284 SIMPLE(double, SHORT, VarR8FromI2);
285 SIMPLE(double, float, VarR8FromR4);
286 RETTYP _VarR8FromCy(CY i, double* o) { *o = (double)i.int64 / CY_MULTIPLIER_F; return S_OK; }
287 SIMPLE(double, DATE, VarR8FromDate);
288 #define _VarR8FromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_R8)
289 #define _VarR8FromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_R8)
290 #define _VarR8FromBool _VarR8FromI2
291 SIMPLE(double, signed char, VarR8FromI1);
292 SIMPLE(double, USHORT, VarR8FromUI2);
293 SIMPLE(double, LONG, VarR8FromI4);
294 SIMPLE(double, ULONG, VarR8FromUI4);
295 #define _VarR8FromDec VarR8FromDec
296 SIMPLE(double, LONG64, VarR8FromI8);
297 SIMPLE(double, ULONG64, VarR8FromUI8);
299 /* BOOL */
300 #define BOOLFUNC(src, func) RETTYP _##func(src in, VARIANT_BOOL* out) { \
301 *out = in ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; }
303 BOOLFUNC(signed char,VarBoolFromI1);
304 BOOLFUNC(BYTE,VarBoolFromUI1);
305 BOOLFUNC(SHORT,VarBoolFromI2);
306 BOOLFUNC(USHORT,VarBoolFromUI2);
307 BOOLFUNC(LONG,VarBoolFromI4);
308 BOOLFUNC(ULONG,VarBoolFromUI4);
309 BOOLFUNC(LONG64,VarBoolFromI8);
310 BOOLFUNC(ULONG64,VarBoolFromUI8);
311 #define _VarBoolFromR4(flt,out) _VarBoolFromR8((double)flt,out)
312 BOOLFUNC(double,VarBoolFromR8);
313 #define _VarBoolFromCy(i,o) _VarBoolFromI8(i.int64,o)
314 #define _VarBoolFromDate(dt,out) _VarBoolFromR8((double)dt,out)
315 #define _VarBoolFromStr VarBoolFromStr
316 #define _VarBoolFromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, (BYTE*)out, VT_BOOL)
317 #define _VarBoolFromDec VarBoolFromDec
319 /* Internal flags for low level conversion functions */
320 #define VAR_BOOLONOFF 0x0400 /* Convert bool to "On"/"Off" */
321 #define VAR_BOOLYESNO 0x0800 /* Convert bool to "Yes"/"No" */
322 #define VAR_NEGATIVE 0x1000 /* Number is negative */
324 /* DECIMAL */
325 #define _VarDecFromUI1 VarDecFromUI4
326 #define _VarDecFromI2 VarDecFromI4
327 #define _VarDecFromR4 VarDecFromR4
328 #define _VarDecFromR8 VarDecFromR8
329 #define _VarDecFromCy VarDecFromCy
330 #define _VarDecFromDate(dt,out) VarDecFromR8((double)dt,out)
331 #define _VarDecFromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_DECIMAL)
332 #define _VarDecFromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_DECIMAL)
333 #define _VarDecFromBool VarDecFromBool
334 #define _VarDecFromI1 VarDecFromI4
335 #define _VarDecFromUI2 VarDecFromUI4
336 #define _VarDecFromI4 VarDecFromI4
337 #define _VarDecFromUI4 VarDecFromUI4
338 #define _VarDecFromI8 VarDecFromI8
339 #define _VarDecFromUI8 VarDecFromUI8
341 /* CY (Currency) */
342 #define _VarCyFromUI1 VarCyFromR8
343 #define _VarCyFromI2 VarCyFromR8
344 #define _VarCyFromR4 VarCyFromR8
345 #define _VarCyFromR8 VarCyFromR8
346 #define _VarCyFromDate VarCyFromR8
347 #define _VarCyFromStr(str,lcid,flags,out) VARIANT_NumberFromBstr(str,lcid,flags,(BYTE*)out,VT_CY)
348 #define _VarCyFromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_CY)
349 #define _VarCyFromBool VarCyFromR8
350 #define _VarCyFromI1 VarCyFromR8
351 #define _VarCyFromUI2 VarCyFromR8
352 #define _VarCyFromI4 VarCyFromR8
353 #define _VarCyFromUI4 VarCyFromR8
354 #define _VarCyFromDec VarCyFromDec
355 RETTYP _VarCyFromI8(LONG64 i, CY* o) {
356 if (i <= (I8_MIN/CY_MULTIPLIER) || i >= (I8_MAX/CY_MULTIPLIER)) return DISP_E_OVERFLOW;
357 o->int64 = i * CY_MULTIPLIER;
358 return S_OK;
360 #define _VarCyFromUI8 VarCyFromR8
362 /* DATE */
363 #define _VarDateFromUI1 _VarR8FromUI1
364 #define _VarDateFromI2 _VarR8FromI2
365 #define _VarDateFromR4 _VarDateFromR8
366 RETTYP _VarDateFromR8(double i, DATE* o) {
367 if (i <= (DATE_MIN - 1.0) || i >= (DATE_MAX + 1.0)) return DISP_E_OVERFLOW;
368 *o = (DATE)i;
369 return S_OK;
371 #define _VarDateFromCy _VarR8FromCy
372 #define _VarDateFromStr VarDateFromStr
373 #define _VarDateFromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_DATE)
374 #define _VarDateFromBool _VarR8FromBool
375 #define _VarDateFromI1 _VarR8FromI1
376 #define _VarDateFromUI2 _VarR8FromUI2
377 #define _VarDateFromI4 _VarDateFromR8
378 #define _VarDateFromUI4 _VarDateFromR8
379 #define _VarDateFromDec _VarR8FromDec
380 RETTYP _VarDateFromI8(LONG64 i, DATE* o) {
381 if (i < DATE_MIN || i > DATE_MAX) return DISP_E_OVERFLOW;
382 *o = (DATE)i;
383 return S_OK;
385 RETTYP _VarDateFromUI8(ULONG64 i, DATE* o) {
386 if (i > DATE_MAX) return DISP_E_OVERFLOW;
387 *o = (DATE)i;
388 return S_OK;
391 /* BSTR */
392 #define _VarBstrFromUI1 VarBstrFromUI4
393 #define _VarBstrFromI2 VarBstrFromI4
394 #define _VarBstrFromR4 VarBstrFromR8
395 #define _VarBstrFromR8 VarBstrFromR8
396 #define _VarBstrFromCy VarBstrFromCy
397 #define _VarBstrFromDate VarBstrFromDate
398 #define _VarBstrFromDisp(disp,lcid,out) VARIANT_FromDisp(disp, lcid, out, VT_BSTR)
399 #define _VarBstrFromBool VarBstrFromBool
400 #define _VarBstrFromI1 VarBstrFromI4
401 #define _VarBstrFromUI2 VarBstrFromUI4
402 #define _VarBstrFromI4 VarBstrFromI4
403 #define _VarBstrFromUI4 VarBstrFromUI4
404 #define _VarBstrFromDec VarBstrFromDec
405 #define _VarBstrFromI8 VarBstrFromI8
406 #define _VarBstrFromUI8 VarBstrFromUI8
408 /* Macro to inline conversion from a float or double to any integer type,
409 * rounding according to the 'dutch' convention.
411 #define OLEAUT32_DutchRound(typ, value, res) do { \
412 double whole = (double)value < 0 ? ceil((double)value) : floor((double)value); \
413 double fract = (double)value - whole; \
414 if (fract > 0.5) res = (typ)whole + (typ)1; \
415 else if (fract == 0.5) { typ is_odd = (typ)whole & 1; res = whole + is_odd; } \
416 else if (fract >= 0.0) res = (typ)whole; \
417 else if (fract == -0.5) { typ is_odd = (typ)whole & 1; res = whole - is_odd; } \
418 else if (fract > -0.5) res = (typ)whole; \
419 else res = (typ)whole - (typ)1; \
420 } while(0);
422 /* The localised characters that make up a valid number */
423 typedef struct tagVARIANT_NUMBER_CHARS
425 WCHAR cNegativeSymbol;
426 WCHAR cPositiveSymbol;
427 WCHAR cDecimalPoint;
428 WCHAR cDigitSeperator;
429 WCHAR cCurrencyLocal;
430 WCHAR cCurrencyLocal2;
431 WCHAR cCurrencyDecimalPoint;
432 WCHAR cCurrencyDigitSeperator;
433 } VARIANT_NUMBER_CHARS;
435 void VARIANT_GetLocalisedNumberChars(VARIANT_NUMBER_CHARS*,LCID,DWORD);