4 * Copyright 1998 Jean-Claude Cote
7 * This implements the low-level and hi-level APIs for manipulating VARIANTs.
8 * The low-level APIs are used to do data coercion between different data types.
9 * The hi-level APIs are built on top of these low-level APIs and handle
10 * initialization, copying, destroying and changing the type of VARIANTs.
13 * - The Variant APIs do not support international languages, currency
14 * types, number formating and calendar. They only support U.S. English format.
15 * - The Variant APIs do not the following types: IUknown, IDispatch, DECIMAL and SafeArray.
16 * The prototypes for these are commented out in the oleauto.h file. They need
17 * to be implemented and cases need to be added to the switches of the existing APIs.
18 * - The parsing of date for the VarDateFromStr is not complete.
19 * - The date manipulations do not support dates prior to 1900.
20 * - The parsing does not accept as many formats as the Windows implementation.
38 #include "debugtools.h"
42 DEFAULT_DEBUG_CHANNEL(ole);
44 #define SYSDUPSTRING(str) SysAllocStringLen((str), SysStringLen(str))
48 # define FLT_MAX MAXFLOAT
50 # error "Can't find #define for MAXFLOAT/FLT_MAX"
56 static const char CHAR_MAX = 127;
57 static const char CHAR_MIN = -128;
58 static const BYTE UI1_MAX = 255;
59 static const BYTE UI1_MIN = 0;
60 static const unsigned short UI2_MAX = 65535;
61 static const unsigned short UI2_MIN = 0;
62 static const short I2_MAX = 32767;
63 static const short I2_MIN = -32768;
64 static const unsigned long UI4_MAX = 4294967295U;
65 static const unsigned long UI4_MIN = 0;
66 static const long I4_MAX = 2147483647;
67 static const long I4_MIN = -(2147483648U);
68 static const DATE DATE_MIN = -657434;
69 static const DATE DATE_MAX = 2958465;
72 /* This mask is used to set a flag in wReserved1 of
73 * the VARIANTARG structure. The flag indicates if
74 * the API function is using an inner variant or not.
76 #define PROCESSING_INNER_VARIANT 0x0001
78 /* General use buffer.
80 #define BUFFER_MAX 1024
81 static char pBuffer[BUFFER_MAX];
84 * Note a leap year is one that is a multiple of 4
85 * but not of a 100. Except if it is a multiple of
86 * 400 then it is a leap year.
88 /* According to postgreSQL date parsing functions there is
89 * a leap year when this expression is true.
90 * (((y % 4) == 0) && (((y % 100) != 0) || ((y % 400) == 0)))
91 * So according to this there is 365.2515 days in one year.
92 * One + every four years: 1/4 -> 365.25
93 * One - every 100 years: 1/100 -> 365.01
94 * One + every 400 years: 1/400 -> 365.0025
96 /* static const double DAYS_IN_ONE_YEAR = 365.2515;
98 * ^^ Might this be the key to an easy way to factor large prime numbers?
99 * Let's try using arithmetic. <lawson_whitney@juno.com> 7 Mar 2000
101 static const double DAYS_IN_ONE_YEAR = 365.2425;
104 /******************************************************************************
105 * DateTimeStringToTm [INTERNAL]
107 * Converts a string representation of a date and/or time to a tm structure.
109 * Note this function uses the postgresql date parsing functions found
110 * in the parsedt.c file.
112 * Returns TRUE if successful.
114 * Note: This function does not parse the day of the week,
115 * daylight savings time. It will only fill the followin fields in
116 * the tm struct, tm_sec, tm_min, tm_hour, tm_year, tm_day, tm_mon.
118 ******************************************************************************/
119 static BOOL DateTimeStringToTm( OLECHAR* strIn, DWORD dwFlags, struct tm* pTm )
126 char *field[MAXDATEFIELDS];
127 int ftype[MAXDATEFIELDS];
128 char lowstr[MAXDATELEN + 1];
129 char* strDateTime = NULL;
131 /* Convert the string to ASCII since this is the only format
132 * postgesql can handle.
134 strDateTime = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
136 if( strDateTime != NULL )
138 /* Make sure we don't go over the maximum length
139 * accepted by postgesql.
141 if( strlen( strDateTime ) <= MAXDATELEN )
143 if( ParseDateTime( strDateTime, lowstr, field, ftype, MAXDATEFIELDS, &nf) == 0 )
145 if( dwFlags & VAR_DATEVALUEONLY )
147 /* Get the date information.
148 * It returns 0 if date information was
149 * present and 1 if only time information was present.
150 * -1 if an error occures.
152 if( DecodeDateTime(field, ftype, nf, &dtype, pTm, &fsec, &tzp) == 0 )
154 /* Eliminate the time information since we
155 * were asked to get date information only.
163 if( dwFlags & VAR_TIMEVALUEONLY )
165 /* Get time information only.
167 if( DecodeTimeOnly(field, ftype, nf, &dtype, pTm, &fsec) == 0 )
174 /* Get both date and time information.
175 * It returns 0 if date information was
176 * present and 1 if only time information was present.
177 * -1 if an error occures.
179 if( DecodeDateTime(field, ftype, nf, &dtype, pTm, &fsec, &tzp) != -1 )
186 HeapFree( GetProcessHeap(), 0, strDateTime );
197 /******************************************************************************
198 * TmToDATE [INTERNAL]
200 * The date is implemented using an 8 byte floating-point number.
201 * Days are represented by whole numbers increments starting with 0.00 has
202 * being December 30 1899, midnight.
203 * The hours are expressed as the fractional part of the number.
204 * December 30 1899 at midnight = 0.00
205 * January 1 1900 at midnight = 2.00
206 * January 4 1900 at 6 AM = 5.25
207 * January 4 1900 at noon = 5.50
208 * December 29 1899 at midnight = -1.00
209 * December 18 1899 at midnight = -12.00
210 * December 18 1899 at 6AM = -12.25
211 * December 18 1899 at 6PM = -12.75
212 * December 19 1899 at midnight = -11.00
213 * The tm structure is as follows:
215 * int tm_sec; seconds after the minute - [0,59]
216 * int tm_min; minutes after the hour - [0,59]
217 * int tm_hour; hours since midnight - [0,23]
218 * int tm_mday; day of the month - [1,31]
219 * int tm_mon; months since January - [0,11]
221 * int tm_wday; days since Sunday - [0,6]
222 * int tm_yday; days since January 1 - [0,365]
223 * int tm_isdst; daylight savings time flag
226 * Note: This function does not use the tm_wday, tm_yday, tm_wday,
227 * and tm_isdst fields of the tm structure. And only converts years
230 * Returns TRUE if successful.
232 static BOOL TmToDATE( struct tm* pTm, DATE *pDateOut )
236 if( (pTm->tm_year - 1900) < 0 ) return FALSE;
238 /* Start at 1. This is the way DATE is defined.
239 * January 1, 1900 at Midnight is 1.00.
240 * January 1, 1900 at 6AM is 1.25.
245 /* Add the number of days corresponding to
248 *pDateOut += (pTm->tm_year - 1900) * 365;
250 /* Add the leap days in the previous years between now and 1900.
251 * Note a leap year is one that is a multiple of 4
252 * but not of a 100. Except if it is a multiple of
253 * 400 then it is a leap year.
255 *pDateOut += ( (pTm->tm_year - 1) / 4 ) - ( 1900 / 4 );
256 *pDateOut -= ( (pTm->tm_year - 1) / 100 ) - ( 1900 / 100 );
257 *pDateOut += ( (pTm->tm_year - 1) / 400 ) - ( 1900 / 400 );
259 /* Set the leap year flag if the
260 * current year specified by tm_year is a
261 * leap year. This will be used to add a day
264 if( isleap( pTm->tm_year ) )
267 /* Add the number of days corresponding to
270 switch( pTm->tm_mon )
276 *pDateOut += ( 59 + leapYear );
279 *pDateOut += ( 90 + leapYear );
282 *pDateOut += ( 120 + leapYear );
285 *pDateOut += ( 151 + leapYear );
288 *pDateOut += ( 181 + leapYear );
291 *pDateOut += ( 212 + leapYear );
294 *pDateOut += ( 243 + leapYear );
297 *pDateOut += ( 273 + leapYear );
300 *pDateOut += ( 304 + leapYear );
303 *pDateOut += ( 334 + leapYear );
306 /* Add the number of days in this month.
308 *pDateOut += pTm->tm_mday;
310 /* Add the number of seconds, minutes, and hours
311 * to the DATE. Note these are the fracionnal part
312 * of the DATE so seconds / number of seconds in a day.
314 *pDateOut += pTm->tm_hour / 24.0;
315 *pDateOut += pTm->tm_min / 1440.0;
316 *pDateOut += pTm->tm_sec / 86400.0;
320 /******************************************************************************
321 * DateToTm [INTERNAL]
323 * This function converts a windows DATE to a tm structure.
325 * It does not fill all the fields of the tm structure.
326 * Here is a list of the fields that are filled:
327 * tm_sec, tm_min, tm_hour, tm_year, tm_day, tm_mon.
329 * Note this function does not support dates before the January 1, 1900
330 * or ( dateIn < 2.0 ).
332 * Returns TRUE if successful.
334 static BOOL DateToTm( DATE dateIn, DWORD dwFlags, struct tm* pTm )
336 double decimalPart = 0.0;
337 double wholePart = 0.0;
339 /* Do not process dates smaller than January 1, 1900.
340 * Which corresponds to 2.0 in the windows DATE format.
342 if( dateIn < 2.0 ) return FALSE;
344 memset(pTm,0,sizeof(*pTm));
346 /* Because of the nature of DATE format which
347 * associates 2.0 to January 1, 1900. We will
348 * remove 1.0 from the whole part of the DATE
349 * so that in the following code 1.0
350 * will correspond to January 1, 1900.
351 * This simplifies the processing of the DATE value.
355 wholePart = (double) floor( dateIn );
356 decimalPart = fmod( dateIn, wholePart );
358 if( !(dwFlags & VAR_TIMEVALUEONLY) )
362 double yearsSince1900 = 0;
363 /* Start at 1900, this is where the DATE time 0.0 starts.
366 /* find in what year the day in the "wholePart" falls into.
367 * add the value to the year field.
369 yearsSince1900 = floor( (wholePart / DAYS_IN_ONE_YEAR) + 0.001 );
370 pTm->tm_year += yearsSince1900;
371 /* determine if this is a leap year.
373 if( isleap( pTm->tm_year ) )
379 /* find what day of that year the "wholePart" corresponds to.
380 * Note: nDay is in [1-366] format
382 nDay = (int) ( wholePart - floor( yearsSince1900 * DAYS_IN_ONE_YEAR ) );
383 /* Set the tm_yday value.
384 * Note: The day must be converted from [1-366] to [0-365]
386 /*pTm->tm_yday = nDay - 1;*/
387 /* find which month this day corresponds to.
394 else if( nDay <= ( 59 + leapYear ) )
396 pTm->tm_mday = nDay - 31;
399 else if( nDay <= ( 90 + leapYear ) )
401 pTm->tm_mday = nDay - ( 59 + leapYear );
404 else if( nDay <= ( 120 + leapYear ) )
406 pTm->tm_mday = nDay - ( 90 + leapYear );
409 else if( nDay <= ( 151 + leapYear ) )
411 pTm->tm_mday = nDay - ( 120 + leapYear );
414 else if( nDay <= ( 181 + leapYear ) )
416 pTm->tm_mday = nDay - ( 151 + leapYear );
419 else if( nDay <= ( 212 + leapYear ) )
421 pTm->tm_mday = nDay - ( 181 + leapYear );
424 else if( nDay <= ( 243 + leapYear ) )
426 pTm->tm_mday = nDay - ( 212 + leapYear );
429 else if( nDay <= ( 273 + leapYear ) )
431 pTm->tm_mday = nDay - ( 243 + leapYear );
434 else if( nDay <= ( 304 + leapYear ) )
436 pTm->tm_mday = nDay - ( 273 + leapYear );
439 else if( nDay <= ( 334 + leapYear ) )
441 pTm->tm_mday = nDay - ( 304 + leapYear );
444 else if( nDay <= ( 365 + leapYear ) )
446 pTm->tm_mday = nDay - ( 334 + leapYear );
450 if( !(dwFlags & VAR_DATEVALUEONLY) )
452 /* find the number of seconds in this day.
453 * fractional part times, hours, minutes, seconds.
455 pTm->tm_hour = (int) ( decimalPart * 24 );
456 pTm->tm_min = (int) ( ( ( decimalPart * 24 ) - pTm->tm_hour ) * 60 );
457 pTm->tm_sec = (int) ( ( ( decimalPart * 24 * 60 ) - ( pTm->tm_hour * 60 ) - pTm->tm_min ) * 60 );
464 /******************************************************************************
465 * SizeOfVariantData [INTERNAL]
467 * This function finds the size of the data referenced by a Variant based
468 * the type "vt" of the Variant.
470 static int SizeOfVariantData( VARIANT* parg )
473 switch( V_VT(parg) & VT_TYPEMASK )
476 size = sizeof(short);
488 size = sizeof(unsigned short);
491 size = sizeof(unsigned int);
494 size = sizeof(unsigned long);
497 size = sizeof(float);
500 size = sizeof(double);
506 size = sizeof(VARIANT_BOOL);
509 size = sizeof(void*);
516 FIXME("Add size information for type vt=%d\n", V_VT(parg) & VT_TYPEMASK );
522 /******************************************************************************
523 * StringDupAtoBstr [INTERNAL]
526 static BSTR StringDupAtoBstr( char* strIn )
529 OLECHAR* pNewString = NULL;
530 pNewString = HEAP_strdupAtoW( GetProcessHeap(), 0, strIn );
531 bstr = SysAllocString( pNewString );
532 HeapFree( GetProcessHeap(), 0, pNewString );
536 /******************************************************************************
539 * Round the double value to the nearest integer value.
541 static double round( double d )
543 double decimals = 0.0, integerValue = 0.0, roundedValue = 0.0;
544 BOOL bEvenNumber = FALSE;
547 /* Save the sign of the number
549 nSign = (d >= 0.0) ? 1 : -1;
552 /* Remove the decimals.
554 integerValue = floor( d );
556 /* Set the Even flag. This is used to round the number when
557 * the decimals are exactly 1/2. If the integer part is
558 * odd the number is rounded up. If the integer part
559 * is even the number is rounded down. Using this method
560 * numbers are rounded up|down half the time.
562 bEvenNumber = (((short)fmod(integerValue, 2)) == 0) ? TRUE : FALSE;
564 /* Remove the integral part of the number.
566 decimals = d - integerValue;
568 /* Note: Ceil returns the smallest integer that is greater that x.
569 * and floor returns the largest integer that is less than or equal to x.
573 /* If the decimal part is greater than 1/2
575 roundedValue = ceil( d );
577 else if( decimals < 0.5 )
579 /* If the decimal part is smaller than 1/2
581 roundedValue = floor( d );
585 /* the decimals are exactly 1/2 so round according to
586 * the bEvenNumber flag.
590 roundedValue = floor( d );
594 roundedValue = ceil( d );
598 return roundedValue * nSign;
601 /******************************************************************************
602 * RemoveCharacterFromString [INTERNAL]
604 * Removes any of the characters in "strOfCharToRemove" from the "str" argument.
606 static void RemoveCharacterFromString( LPSTR str, LPSTR strOfCharToRemove )
608 LPSTR pNewString = NULL;
609 LPSTR strToken = NULL;
611 /* Check if we have a valid argument
615 pNewString = strdup( str );
617 strToken = strtok( pNewString, strOfCharToRemove );
618 while( strToken != NULL ) {
619 strcat( str, strToken );
620 strToken = strtok( NULL, strOfCharToRemove );
627 /******************************************************************************
628 * GetValidRealString [INTERNAL]
630 * Checks if the string is of proper format to be converted to a real value.
632 static BOOL IsValidRealString( LPSTR strRealString )
634 /* Real values that have a decimal point are required to either have
635 * digits before or after the decimal point. We will assume that
636 * we do not have any digits at either position. If we do encounter
637 * some we will disable this flag.
639 BOOL bDigitsRequired = TRUE;
640 /* Processed fields in the string representation of the real number.
642 BOOL bWhiteSpaceProcessed = FALSE;
643 BOOL bFirstSignProcessed = FALSE;
644 BOOL bFirstDigitsProcessed = FALSE;
645 BOOL bDecimalPointProcessed = FALSE;
646 BOOL bSecondDigitsProcessed = FALSE;
647 BOOL bExponentProcessed = FALSE;
648 BOOL bSecondSignProcessed = FALSE;
649 BOOL bThirdDigitsProcessed = FALSE;
650 /* Assume string parameter "strRealString" is valid and try to disprove it.
652 BOOL bValidRealString = TRUE;
654 /* Used to count the number of tokens in the "strRealString".
656 LPSTR strToken = NULL;
660 /* Check if we have a valid argument
662 if( strRealString == NULL )
664 bValidRealString = FALSE;
667 if( bValidRealString == TRUE )
669 /* Make sure we only have ONE token in the string.
671 strToken = strtok( strRealString, " " );
672 while( strToken != NULL ) {
674 strToken = strtok( NULL, " " );
679 bValidRealString = FALSE;
684 /* Make sure this token contains only valid characters.
685 * The string argument to atof has the following form:
686 * [whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits]
687 * Whitespace consists of space and|or <TAB> characters, which are ignored.
688 * Sign is either plus '+' or minus '-'.
689 * Digits are one or more decimal digits.
690 * Note: If no digits appear before the decimal point, at least one must
691 * appear after the decimal point.
692 * The decimal digits may be followed by an exponent.
693 * An Exponent consists of an introductory letter ( D, d, E, or e) and
694 * an optionally signed decimal integer.
696 pChar = strRealString;
697 while( bValidRealString == TRUE && *pChar != '\0' )
705 if( bWhiteSpaceProcessed ||
706 bFirstSignProcessed ||
707 bFirstDigitsProcessed ||
708 bDecimalPointProcessed ||
709 bSecondDigitsProcessed ||
710 bExponentProcessed ||
711 bSecondSignProcessed ||
712 bThirdDigitsProcessed )
714 bValidRealString = FALSE;
721 if( bFirstSignProcessed == FALSE )
723 if( bFirstDigitsProcessed ||
724 bDecimalPointProcessed ||
725 bSecondDigitsProcessed ||
726 bExponentProcessed ||
727 bSecondSignProcessed ||
728 bThirdDigitsProcessed )
730 bValidRealString = FALSE;
732 bWhiteSpaceProcessed = TRUE;
733 bFirstSignProcessed = TRUE;
735 else if( bSecondSignProcessed == FALSE )
737 /* Note: The exponent must be present in
738 * order to accept the second sign...
740 if( bExponentProcessed == FALSE ||
741 bThirdDigitsProcessed ||
744 bValidRealString = FALSE;
746 bFirstSignProcessed = TRUE;
747 bWhiteSpaceProcessed = TRUE;
748 bFirstDigitsProcessed = TRUE;
749 bDecimalPointProcessed = TRUE;
750 bSecondDigitsProcessed = TRUE;
751 bSecondSignProcessed = TRUE;
767 if( bFirstDigitsProcessed == FALSE )
769 if( bDecimalPointProcessed ||
770 bSecondDigitsProcessed ||
771 bExponentProcessed ||
772 bSecondSignProcessed ||
773 bThirdDigitsProcessed )
775 bValidRealString = FALSE;
777 bFirstSignProcessed = TRUE;
778 bWhiteSpaceProcessed = TRUE;
779 /* We have found some digits before the decimal point
780 * so disable the "Digits required" flag.
782 bDigitsRequired = FALSE;
784 else if( bSecondDigitsProcessed == FALSE )
786 if( bExponentProcessed ||
787 bSecondSignProcessed ||
788 bThirdDigitsProcessed )
790 bValidRealString = FALSE;
792 bFirstSignProcessed = TRUE;
793 bWhiteSpaceProcessed = TRUE;
794 bFirstDigitsProcessed = TRUE;
795 bDecimalPointProcessed = TRUE;
796 /* We have found some digits after the decimal point
797 * so disable the "Digits required" flag.
799 bDigitsRequired = FALSE;
801 else if( bThirdDigitsProcessed == FALSE )
803 /* Getting here means everything else should be processed.
804 * If we get anything else than a decimal following this
805 * digit it will be flagged by the other cases, so
806 * we do not really need to do anything in here.
810 /* If DecimalPoint...
813 if( bDecimalPointProcessed ||
814 bSecondDigitsProcessed ||
815 bExponentProcessed ||
816 bSecondSignProcessed ||
817 bThirdDigitsProcessed )
819 bValidRealString = FALSE;
821 bFirstSignProcessed = TRUE;
822 bWhiteSpaceProcessed = TRUE;
823 bFirstDigitsProcessed = TRUE;
824 bDecimalPointProcessed = TRUE;
832 if( bExponentProcessed ||
833 bSecondSignProcessed ||
834 bThirdDigitsProcessed ||
837 bValidRealString = FALSE;
839 bFirstSignProcessed = TRUE;
840 bWhiteSpaceProcessed = TRUE;
841 bFirstDigitsProcessed = TRUE;
842 bDecimalPointProcessed = TRUE;
843 bSecondDigitsProcessed = TRUE;
844 bExponentProcessed = TRUE;
847 bValidRealString = FALSE;
850 /* Process next character.
855 /* If the required digits were not present we have an invalid
856 * string representation of a real number.
858 if( bDigitsRequired == TRUE )
860 bValidRealString = FALSE;
863 return bValidRealString;
867 /******************************************************************************
870 * This function dispatches execution to the proper conversion API
871 * to do the necessary coercion.
873 * FIXME: Passing down dwFlags to the conversion functions is wrong, this
874 * is a different flagmask. Check MSDN.
876 static HRESULT Coerce( VARIANTARG* pd, LCID lcid, ULONG dwFlags, VARIANTARG* ps, VARTYPE vt )
879 unsigned short vtFrom = 0;
880 vtFrom = V_VT(ps) & VT_TYPEMASK;
883 /* Note: Since "long" and "int" values both have 4 bytes and are
884 * both signed integers "int" will be treated as "long" in the
886 * The same goes for their unsigned versions.
889 /* Trivial Case: If the coercion is from two types that are
890 * identical then we can blindly copy from one argument to another.*/
893 return VariantCopy(pd,ps);
896 /* Cases requiring thought*/
901 res = VariantClear( pd );
904 res = VariantClear( pd );
914 res = VariantCopy( pd, ps );
917 res = VarI1FromI2( V_UNION(ps,iVal), &V_UNION(pd,cVal) );
921 res = VarI1FromI4( V_UNION(ps,lVal), &V_UNION(pd,cVal) );
924 res = VarI1FromUI1( V_UNION(ps,bVal), &V_UNION(pd,cVal) );
927 res = VarI1FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,cVal) );
931 res = VarI1FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,cVal) );
934 res = VarI1FromR4( V_UNION(ps,fltVal), &V_UNION(pd,cVal) );
937 res = VarI1FromR8( V_UNION(ps,dblVal), &V_UNION(pd,cVal) );
940 res = VarI1FromDate( V_UNION(ps,date), &V_UNION(pd,cVal) );
943 res = VarI1FromBool( V_UNION(ps,boolVal), &V_UNION(pd,cVal) );
946 res = VarI1FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,cVal) );
949 res = VarI1FromCy( V_UNION(ps,cyVal), &V_UNION(pd,cVal) );
952 /*res = VarI1FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,cVal) );*/
954 /*res = VarI1FromDec( V_UNION(ps,decVal), &V_UNION(pd,cVal) );*/
957 res = DISP_E_TYPEMISMATCH;
958 FIXME("Coercion from %d to %d\n", vtFrom, vt );
967 res = VarI2FromI1( V_UNION(ps,cVal), &V_UNION(pd,iVal) );
970 res = VariantCopy( pd, ps );
974 res = VarI2FromI4( V_UNION(ps,lVal), &V_UNION(pd,iVal) );
977 res = VarI2FromUI1( V_UNION(ps,bVal), &V_UNION(pd,iVal) );
980 res = VarI2FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,iVal) );
984 res = VarI2FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,iVal) );
987 res = VarI2FromR4( V_UNION(ps,fltVal), &V_UNION(pd,iVal) );
990 res = VarI2FromR8( V_UNION(ps,dblVal), &V_UNION(pd,iVal) );
993 res = VarI2FromDate( V_UNION(ps,date), &V_UNION(pd,iVal) );
996 res = VarI2FromBool( V_UNION(ps,boolVal), &V_UNION(pd,iVal) );
999 res = VarI2FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,iVal) );
1002 res = VarI2FromCy( V_UNION(ps,cyVal), &V_UNION(pd,iVal) );
1004 case( VT_DISPATCH ):
1005 /*res = VarI2FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,iVal) );*/
1007 /*res = VarI2FromDec( V_UNION(ps,deiVal), &V_UNION(pd,iVal) );*/
1010 res = DISP_E_TYPEMISMATCH;
1011 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1021 res = VarI4FromI1( V_UNION(ps,cVal), &V_UNION(pd,lVal) );
1024 res = VarI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,lVal) );
1028 res = VariantCopy( pd, ps );
1031 res = VarI4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,lVal) );
1034 res = VarI4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,lVal) );
1038 res = VarI4FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,lVal) );
1041 res = VarI4FromR4( V_UNION(ps,fltVal), &V_UNION(pd,lVal) );
1044 res = VarI4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,lVal) );
1047 res = VarI4FromDate( V_UNION(ps,date), &V_UNION(pd,lVal) );
1050 res = VarI4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,lVal) );
1053 res = VarI4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,lVal) );
1056 res = VarI4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,lVal) );
1058 case( VT_DISPATCH ):
1059 /*res = VarI4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,lVal) );*/
1061 /*res = VarI4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,lVal) );*/
1064 res = DISP_E_TYPEMISMATCH;
1065 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1074 res = VarUI1FromI1( V_UNION(ps,cVal), &V_UNION(pd,bVal) );
1077 res = VarUI1FromI2( V_UNION(ps,iVal), &V_UNION(pd,bVal) );
1081 res = VarUI1FromI4( V_UNION(ps,lVal), &V_UNION(pd,bVal) );
1084 res = VariantCopy( pd, ps );
1087 res = VarUI1FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,bVal) );
1091 res = VarUI1FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,bVal) );
1094 res = VarUI1FromR4( V_UNION(ps,fltVal), &V_UNION(pd,bVal) );
1097 res = VarUI1FromR8( V_UNION(ps,dblVal), &V_UNION(pd,bVal) );
1100 res = VarUI1FromDate( V_UNION(ps,date), &V_UNION(pd,bVal) );
1103 res = VarUI1FromBool( V_UNION(ps,boolVal), &V_UNION(pd,bVal) );
1106 res = VarUI1FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,bVal) );
1109 res = VarUI1FromCy( V_UNION(ps,cyVal), &V_UNION(pd,bVal) );
1111 case( VT_DISPATCH ):
1112 /*res = VarUI1FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,bVal) );*/
1114 /*res = VarUI1FromDec( V_UNION(ps,deiVal), &V_UNION(pd,bVal) );*/
1117 res = DISP_E_TYPEMISMATCH;
1118 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1127 res = VarUI2FromI1( V_UNION(ps,cVal), &V_UNION(pd,uiVal) );
1130 res = VarUI2FromI2( V_UNION(ps,iVal), &V_UNION(pd,uiVal) );
1134 res = VarUI2FromI4( V_UNION(ps,lVal), &V_UNION(pd,uiVal) );
1137 res = VarUI2FromUI1( V_UNION(ps,bVal), &V_UNION(pd,uiVal) );
1140 res = VariantCopy( pd, ps );
1144 res = VarUI2FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,uiVal) );
1147 res = VarUI2FromR4( V_UNION(ps,fltVal), &V_UNION(pd,uiVal) );
1150 res = VarUI2FromR8( V_UNION(ps,dblVal), &V_UNION(pd,uiVal) );
1153 res = VarUI2FromDate( V_UNION(ps,date), &V_UNION(pd,uiVal) );
1156 res = VarUI2FromBool( V_UNION(ps,boolVal), &V_UNION(pd,uiVal) );
1159 res = VarUI2FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,uiVal) );
1162 res = VarUI2FromCy( V_UNION(ps,cyVal), &V_UNION(pd,uiVal) );
1164 case( VT_DISPATCH ):
1165 /*res = VarUI2FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,uiVal) );*/
1167 /*res = VarUI2FromDec( V_UNION(ps,deiVal), &V_UNION(pd,uiVal) );*/
1170 res = DISP_E_TYPEMISMATCH;
1171 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1181 res = VarUI4FromI1( V_UNION(ps,cVal), &V_UNION(pd,ulVal) );
1184 res = VarUI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,ulVal) );
1188 res = VarUI4FromI4( V_UNION(ps,lVal), &V_UNION(pd,ulVal) );
1191 res = VarUI4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,ulVal) );
1194 res = VarUI4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,ulVal) );
1197 res = VariantCopy( pd, ps );
1200 res = VarUI4FromR4( V_UNION(ps,fltVal), &V_UNION(pd,ulVal) );
1203 res = VarUI4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,ulVal) );
1206 res = VarUI4FromDate( V_UNION(ps,date), &V_UNION(pd,ulVal) );
1209 res = VarUI4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,ulVal) );
1212 res = VarUI4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,ulVal) );
1215 res = VarUI4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,ulVal) );
1217 case( VT_DISPATCH ):
1218 /*res = VarUI4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,ulVal) );*/
1220 /*res = VarUI4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,ulVal) );*/
1223 res = DISP_E_TYPEMISMATCH;
1224 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1233 res = VarR4FromI1( V_UNION(ps,cVal), &V_UNION(pd,fltVal) );
1236 res = VarR4FromI2( V_UNION(ps,iVal), &V_UNION(pd,fltVal) );
1240 res = VarR4FromI4( V_UNION(ps,lVal), &V_UNION(pd,fltVal) );
1243 res = VarR4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,fltVal) );
1246 res = VarR4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,fltVal) );
1250 res = VarR4FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,fltVal) );
1253 res = VariantCopy( pd, ps );
1256 res = VarR4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,fltVal) );
1259 res = VarR4FromDate( V_UNION(ps,date), &V_UNION(pd,fltVal) );
1262 res = VarR4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,fltVal) );
1265 res = VarR4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,fltVal) );
1268 res = VarR4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,fltVal) );
1270 case( VT_DISPATCH ):
1271 /*res = VarR4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,fltVal) );*/
1273 /*res = VarR4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,fltVal) );*/
1276 res = DISP_E_TYPEMISMATCH;
1277 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1286 res = VarR8FromI1( V_UNION(ps,cVal), &V_UNION(pd,dblVal) );
1289 res = VarR8FromI2( V_UNION(ps,iVal), &V_UNION(pd,dblVal) );
1293 res = VarR8FromI4( V_UNION(ps,lVal), &V_UNION(pd,dblVal) );
1296 res = VarR8FromUI1( V_UNION(ps,bVal), &V_UNION(pd,dblVal) );
1299 res = VarR8FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,dblVal) );
1303 res = VarR8FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,dblVal) );
1306 res = VarR8FromR4( V_UNION(ps,fltVal), &V_UNION(pd,dblVal) );
1309 res = VariantCopy( pd, ps );
1312 res = VarR8FromDate( V_UNION(ps,date), &V_UNION(pd,dblVal) );
1315 res = VarR8FromBool( V_UNION(ps,boolVal), &V_UNION(pd,dblVal) );
1318 res = VarR8FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,dblVal) );
1321 res = VarR8FromCy( V_UNION(ps,cyVal), &V_UNION(pd,dblVal) );
1323 case( VT_DISPATCH ):
1324 /*res = VarR8FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,dblVal) );*/
1326 /*res = VarR8FromDec( V_UNION(ps,deiVal), &V_UNION(pd,dblVal) );*/
1329 res = DISP_E_TYPEMISMATCH;
1330 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1339 res = VarDateFromI1( V_UNION(ps,cVal), &V_UNION(pd,date) );
1342 res = VarDateFromI2( V_UNION(ps,iVal), &V_UNION(pd,date) );
1345 res = VarDateFromInt( V_UNION(ps,intVal), &V_UNION(pd,date) );
1348 res = VarDateFromI4( V_UNION(ps,lVal), &V_UNION(pd,date) );
1351 res = VarDateFromUI1( V_UNION(ps,bVal), &V_UNION(pd,date) );
1354 res = VarDateFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,date) );
1357 res = VarDateFromUint( V_UNION(ps,uintVal), &V_UNION(pd,date) );
1360 res = VarDateFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,date) );
1363 res = VarDateFromR4( V_UNION(ps,fltVal), &V_UNION(pd,date) );
1366 res = VarDateFromR8( V_UNION(ps,dblVal), &V_UNION(pd,date) );
1369 res = VariantCopy( pd, ps );
1372 res = VarDateFromBool( V_UNION(ps,boolVal), &V_UNION(pd,date) );
1375 res = VarDateFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,date) );
1378 res = VarDateFromCy( V_UNION(ps,cyVal), &V_UNION(pd,date) );
1380 case( VT_DISPATCH ):
1381 /*res = VarDateFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,date) );*/
1383 /*res = VarDateFromDec( V_UNION(ps,deiVal), &V_UNION(pd,date) );*/
1386 res = DISP_E_TYPEMISMATCH;
1387 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1396 res = VarBoolFromI1( V_UNION(ps,cVal), &V_UNION(pd,boolVal) );
1399 res = VarBoolFromI2( V_UNION(ps,iVal), &V_UNION(pd,boolVal) );
1402 res = VarBoolFromInt( V_UNION(ps,intVal), &V_UNION(pd,boolVal) );
1405 res = VarBoolFromI4( V_UNION(ps,lVal), &V_UNION(pd,boolVal) );
1408 res = VarBoolFromUI1( V_UNION(ps,bVal), &V_UNION(pd,boolVal) );
1411 res = VarBoolFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,boolVal) );
1414 res = VarBoolFromUint( V_UNION(ps,uintVal), &V_UNION(pd,boolVal) );
1417 res = VarBoolFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,boolVal) );
1420 res = VarBoolFromR4( V_UNION(ps,fltVal), &V_UNION(pd,boolVal) );
1423 res = VarBoolFromR8( V_UNION(ps,dblVal), &V_UNION(pd,boolVal) );
1426 res = VarBoolFromDate( V_UNION(ps,date), &V_UNION(pd,boolVal) );
1429 res = VariantCopy( pd, ps );
1432 res = VarBoolFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,boolVal) );
1435 res = VarBoolFromCy( V_UNION(ps,cyVal), &V_UNION(pd,boolVal) );
1437 case( VT_DISPATCH ):
1438 /*res = VarBoolFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,boolVal) );*/
1440 /*res = VarBoolFromDec( V_UNION(ps,deiVal), &V_UNION(pd,boolVal) );*/
1443 res = DISP_E_TYPEMISMATCH;
1444 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1453 if ((V_UNION(pd,bstrVal) = SysAllocStringLen(NULL, 0)))
1456 res = E_OUTOFMEMORY;
1459 res = VarBstrFromI1( V_UNION(ps,cVal), lcid, 0, &V_UNION(pd,bstrVal) );
1462 res = VarBstrFromI2( V_UNION(ps,iVal), lcid, 0, &V_UNION(pd,bstrVal) );
1465 res = VarBstrFromInt( V_UNION(ps,intVal), lcid, 0, &V_UNION(pd,bstrVal) );
1468 res = VarBstrFromI4( V_UNION(ps,lVal), lcid, 0, &V_UNION(pd,bstrVal) );
1471 res = VarBstrFromUI1( V_UNION(ps,bVal), lcid, 0, &V_UNION(pd,bstrVal) );
1474 res = VarBstrFromUI2( V_UNION(ps,uiVal), lcid, 0, &V_UNION(pd,bstrVal) );
1477 res = VarBstrFromUint( V_UNION(ps,uintVal), lcid, 0, &V_UNION(pd,bstrVal) );
1480 res = VarBstrFromUI4( V_UNION(ps,ulVal), lcid, 0, &V_UNION(pd,bstrVal) );
1483 res = VarBstrFromR4( V_UNION(ps,fltVal), lcid, 0, &V_UNION(pd,bstrVal) );
1486 res = VarBstrFromR8( V_UNION(ps,dblVal), lcid, 0, &V_UNION(pd,bstrVal) );
1489 res = VarBstrFromDate( V_UNION(ps,date), lcid, 0, &V_UNION(pd,bstrVal) );
1492 res = VarBstrFromBool( V_UNION(ps,boolVal), lcid, 0, &V_UNION(pd,bstrVal) );
1495 res = VariantCopy( pd, ps );
1498 res = VarBstrFromCy( V_UNION(ps,cyVal), lcid, 0, &V_UNION(pd,bstrVal) );
1500 case( VT_DISPATCH ):
1501 /*res = VarBstrFromDisp( V_UNION(ps,pdispVal), lcid, 0, &(pd,bstrVal) );*/
1503 /*res = VarBstrFromDec( V_UNION(ps,deiVal), lcid, 0, &(pd,bstrVal) );*/
1506 res = DISP_E_TYPEMISMATCH;
1507 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1516 res = VarCyFromI1( V_UNION(ps,cVal), &V_UNION(pd,cyVal) );
1519 res = VarCyFromI2( V_UNION(ps,iVal), &V_UNION(pd,cyVal) );
1522 res = VarCyFromInt( V_UNION(ps,intVal), &V_UNION(pd,cyVal) );
1525 res = VarCyFromI4( V_UNION(ps,lVal), &V_UNION(pd,cyVal) );
1528 res = VarCyFromUI1( V_UNION(ps,bVal), &V_UNION(pd,cyVal) );
1531 res = VarCyFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,cyVal) );
1534 res = VarCyFromUint( V_UNION(ps,uintVal), &V_UNION(pd,cyVal) );
1537 res = VarCyFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,cyVal) );
1540 res = VarCyFromR4( V_UNION(ps,fltVal), &V_UNION(pd,cyVal) );
1543 res = VarCyFromR8( V_UNION(ps,dblVal), &V_UNION(pd,cyVal) );
1546 res = VarCyFromDate( V_UNION(ps,date), &V_UNION(pd,cyVal) );
1549 res = VarCyFromBool( V_UNION(ps,date), &V_UNION(pd,cyVal) );
1552 res = VariantCopy( pd, ps );
1555 res = VarCyFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,cyVal) );
1557 case( VT_DISPATCH ):
1558 /*res = VarCyFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,cyVal) );*/
1560 /*res = VarCyFromDec( V_UNION(ps,deiVal), &V_UNION(pd,cyVal) );*/
1564 res = DISP_E_TYPEMISMATCH;
1565 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1571 res = DISP_E_TYPEMISMATCH;
1572 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1579 /******************************************************************************
1580 * ValidateVtRange [INTERNAL]
1582 * Used internally by the hi-level Variant API to determine
1583 * if the vartypes are valid.
1585 static HRESULT WINAPI ValidateVtRange( VARTYPE vt )
1587 /* if by value we must make sure it is in the
1588 * range of the valid types.
1590 if( ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1592 return DISP_E_BADVARTYPE;
1598 /******************************************************************************
1599 * ValidateVartype [INTERNAL]
1601 * Used internally by the hi-level Variant API to determine
1602 * if the vartypes are valid.
1604 static HRESULT WINAPI ValidateVariantType( VARTYPE vt )
1608 /* check if we have a valid argument.
1612 /* if by reference check that the type is in
1613 * the valid range and that it is not of empty or null type
1615 if( ( vt & VT_TYPEMASK ) == VT_EMPTY ||
1616 ( vt & VT_TYPEMASK ) == VT_NULL ||
1617 ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1625 res = ValidateVtRange( vt );
1631 /******************************************************************************
1632 * ValidateVt [INTERNAL]
1634 * Used internally by the hi-level Variant API to determine
1635 * if the vartypes are valid.
1637 static HRESULT WINAPI ValidateVt( VARTYPE vt )
1641 /* check if we have a valid argument.
1645 /* if by reference check that the type is in
1646 * the valid range and that it is not of empty or null type
1648 if( ( vt & VT_TYPEMASK ) == VT_EMPTY ||
1649 ( vt & VT_TYPEMASK ) == VT_NULL ||
1650 ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1652 res = DISP_E_BADVARTYPE;
1658 res = ValidateVtRange( vt );
1668 /******************************************************************************
1669 * VariantInit [OLEAUT32.8]
1671 * Initializes the Variant. Unlike VariantClear it does not interpret
1672 * the current contents of the Variant.
1674 void WINAPI VariantInit(VARIANTARG* pvarg)
1676 TRACE("(%p)\n",pvarg);
1678 memset(pvarg, 0, sizeof (VARIANTARG));
1679 V_VT(pvarg) = VT_EMPTY;
1684 /******************************************************************************
1685 * VariantClear [OLEAUT32.9]
1687 * This function clears the VARIANT by setting the vt field to VT_EMPTY. It also
1688 * sets the wReservedX field to 0. The current contents of the VARIANT are
1689 * freed. If the vt is VT_BSTR the string is freed. If VT_DISPATCH the object is
1690 * released. If VT_ARRAY the array is freed.
1692 HRESULT WINAPI VariantClear(VARIANTARG* pvarg)
1695 TRACE("(%p)\n",pvarg);
1697 res = ValidateVariantType( V_VT(pvarg) );
1700 if( !( V_VT(pvarg) & VT_BYREF ) )
1703 * The VT_ARRAY flag is a special case of a safe array.
1705 if ( (V_VT(pvarg) & VT_ARRAY) != 0)
1707 SafeArrayDestroy(V_UNION(pvarg,parray));
1711 switch( V_VT(pvarg) & VT_TYPEMASK )
1714 SysFreeString( V_UNION(pvarg,bstrVal) );
1716 case( VT_DISPATCH ):
1717 if(V_UNION(pvarg,pdispVal)!=NULL)
1718 ICOM_CALL(Release,V_UNION(pvarg,pdispVal));
1721 VariantClear(V_UNION(pvarg,pvarVal));
1724 if(V_UNION(pvarg,punkVal)!=NULL)
1725 ICOM_CALL(Release,V_UNION(pvarg,punkVal));
1727 case( VT_SAFEARRAY ):
1728 SafeArrayDestroy(V_UNION(pvarg,parray));
1737 * Empty all the fields and mark the type as empty.
1739 memset(pvarg, 0, sizeof (VARIANTARG));
1740 V_VT(pvarg) = VT_EMPTY;
1746 /******************************************************************************
1747 * VariantCopy [OLEAUT32.10]
1749 * Frees up the designation variant and makes a copy of the source.
1751 HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc)
1755 TRACE("(%p, %p), vt=%d\n", pvargDest, pvargSrc, V_VT(pvargSrc));
1757 res = ValidateVariantType( V_VT(pvargSrc) );
1759 /* If the pointer are to the same variant we don't need
1762 if( pvargDest != pvargSrc && res == S_OK )
1764 res = VariantClear( pvargDest );
1768 if( V_VT(pvargSrc) & VT_BYREF )
1770 /* In the case of byreference we only need
1771 * to copy the pointer.
1773 pvargDest->n1.n2.n3 = pvargSrc->n1.n2.n3;
1774 V_VT(pvargDest) = V_VT(pvargSrc);
1779 * The VT_ARRAY flag is another way to designate a safe array.
1781 if (V_VT(pvargSrc) & VT_ARRAY)
1783 SafeArrayCopy(V_UNION(pvargSrc,parray), &V_UNION(pvargDest,parray));
1787 /* In the case of by value we need to
1788 * copy the actual value. In the case of
1789 * VT_BSTR a copy of the string is made,
1790 * if VT_DISPATCH or VT_IUNKNOWN AddRef is
1791 * called to increment the object's reference count.
1793 switch( V_VT(pvargSrc) & VT_TYPEMASK )
1796 V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( V_UNION(pvargSrc,bstrVal) );
1798 case( VT_DISPATCH ):
1799 V_UNION(pvargDest,pdispVal) = V_UNION(pvargSrc,pdispVal);
1800 if (V_UNION(pvargDest,pdispVal)!=NULL)
1801 ICOM_CALL(AddRef,V_UNION(pvargDest,pdispVal));
1804 VariantCopy(V_UNION(pvargDest,pvarVal),V_UNION(pvargSrc,pvarVal));
1807 V_UNION(pvargDest,punkVal) = V_UNION(pvargSrc,punkVal);
1808 if (V_UNION(pvargDest,pdispVal)!=NULL)
1809 ICOM_CALL(AddRef,V_UNION(pvargDest,punkVal));
1811 case( VT_SAFEARRAY ):
1812 SafeArrayCopy(V_UNION(pvargSrc,parray), &V_UNION(pvargDest,parray));
1815 pvargDest->n1.n2.n3 = pvargSrc->n1.n2.n3;
1820 V_VT(pvargDest) = V_VT(pvargSrc);
1829 /******************************************************************************
1830 * VariantCopyInd [OLEAUT32.11]
1832 * Frees up the destination variant and makes a copy of the source. If
1833 * the source is of type VT_BYREF it performs the necessary indirections.
1835 HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc)
1839 TRACE("(%p, %p)\n", pvargDest, pvargSrc);
1841 res = ValidateVariantType( V_VT(pvargSrc) );
1846 if( V_VT(pvargSrc) & VT_BYREF )
1849 VariantInit( &varg );
1851 /* handle the in place copy.
1853 if( pvargDest == pvargSrc )
1855 /* we will use a copy of the source instead.
1857 res = VariantCopy( &varg, pvargSrc );
1863 res = VariantClear( pvargDest );
1868 * The VT_ARRAY flag is another way to designate a safearray variant.
1870 if ( V_VT(pvargSrc) & VT_ARRAY)
1872 SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
1876 /* In the case of by reference we need
1877 * to copy the date pointed to by the variant.
1880 /* Get the variant type.
1882 switch( V_VT(pvargSrc) & VT_TYPEMASK )
1885 V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( *(V_UNION(pvargSrc,pbstrVal)) );
1887 case( VT_DISPATCH ):
1891 /* Prevent from cycling. According to tests on
1892 * VariantCopyInd in Windows and the documentation
1893 * this API dereferences the inner Variants to only one depth.
1894 * If the inner Variant itself contains an
1895 * other inner variant the E_INVALIDARG error is
1898 if( pvargSrc->n1.n2.wReserved1 & PROCESSING_INNER_VARIANT )
1900 /* If we get here we are attempting to deference
1901 * an inner variant that that is itself contained
1902 * in an inner variant so report E_INVALIDARG error.
1908 /* Set the processing inner variant flag.
1909 * We will set this flag in the inner variant
1910 * that will be passed to the VariantCopyInd function.
1912 (V_UNION(pvargSrc,pvarVal))->n1.n2.wReserved1 |= PROCESSING_INNER_VARIANT;
1914 /* Dereference the inner variant.
1916 res = VariantCopyInd( pvargDest, V_UNION(pvargSrc,pvarVal) );
1917 /* We must also copy its type, I think.
1919 V_VT(pvargSrc) = V_VT(V_UNION(pvargSrc,pvarVal));
1925 case( VT_SAFEARRAY ):
1926 SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
1929 /* This is a by reference Variant which means that the union
1930 * part of the Variant contains a pointer to some data of
1931 * type "V_VT(pvargSrc) & VT_TYPEMASK".
1932 * We will deference this data in a generic fashion using
1933 * the void pointer "Variant.u.byref".
1934 * We will copy this data into the union of the destination
1937 memcpy( &pvargDest->n1.n2, V_UNION(pvargSrc,byref), SizeOfVariantData( pvargSrc ) );
1942 V_VT(pvargDest) = V_VT(pvargSrc) & VT_TYPEMASK;
1946 /* this should not fail.
1948 VariantClear( &varg );
1952 res = VariantCopy( pvargDest, pvargSrc );
1958 /******************************************************************************
1959 * VariantChangeType [OLEAUT32.12]
1961 HRESULT WINAPI VariantChangeType(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
1962 USHORT wFlags, VARTYPE vt)
1964 return VariantChangeTypeEx( pvargDest, pvargSrc, 0, wFlags, vt );
1967 /******************************************************************************
1968 * VariantChangeTypeEx [OLEAUT32.147]
1970 HRESULT WINAPI VariantChangeTypeEx(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
1971 LCID lcid, USHORT wFlags, VARTYPE vt)
1975 VariantInit( &varg );
1977 TRACE("(%p, %p, %ld, %u, %u) vt=%d\n", pvargDest, pvargSrc, lcid, wFlags, vt, V_VT(pvargSrc));
1979 /* validate our source argument.
1981 res = ValidateVariantType( V_VT(pvargSrc) );
1983 /* validate the vartype.
1987 res = ValidateVt( vt );
1990 /* if we are doing an in-place conversion make a copy of the source.
1992 if( res == S_OK && pvargDest == pvargSrc )
1994 res = VariantCopy( &varg, pvargSrc );
2000 /* free up the destination variant.
2002 res = VariantClear( pvargDest );
2007 if( V_VT(pvargSrc) & VT_BYREF )
2009 /* Convert the source variant to a "byvalue" variant.
2012 VariantInit( &Variant );
2013 res = VariantCopyInd( &Variant, pvargSrc );
2016 res = Coerce( pvargDest, lcid, wFlags, &Variant, vt );
2017 /* this should not fail.
2019 VariantClear( &Variant );
2025 /* Use the current "byvalue" source variant.
2027 res = Coerce( pvargDest, lcid, wFlags, pvargSrc, vt );
2030 /* this should not fail.
2032 VariantClear( &varg );
2034 /* set the type of the destination
2037 V_VT(pvargDest) = vt;
2045 /******************************************************************************
2046 * VarUI1FromI2 [OLEAUT32.130]
2048 HRESULT WINAPI VarUI1FromI2(short sIn, BYTE* pbOut)
2050 TRACE("( %d, %p ), stub\n", sIn, pbOut );
2052 /* Check range of value.
2054 if( sIn < UI1_MIN || sIn > UI1_MAX )
2056 return DISP_E_OVERFLOW;
2059 *pbOut = (BYTE) sIn;
2064 /******************************************************************************
2065 * VarUI1FromI4 [OLEAUT32.131]
2067 HRESULT WINAPI VarUI1FromI4(LONG lIn, BYTE* pbOut)
2069 TRACE("( %ld, %p ), stub\n", lIn, pbOut );
2071 /* Check range of value.
2073 if( lIn < UI1_MIN || lIn > UI1_MAX )
2075 return DISP_E_OVERFLOW;
2078 *pbOut = (BYTE) lIn;
2084 /******************************************************************************
2085 * VarUI1FromR4 [OLEAUT32.132]
2087 HRESULT WINAPI VarUI1FromR4(FLOAT fltIn, BYTE* pbOut)
2089 TRACE("( %f, %p ), stub\n", fltIn, pbOut );
2091 /* Check range of value.
2093 fltIn = round( fltIn );
2094 if( fltIn < UI1_MIN || fltIn > UI1_MAX )
2096 return DISP_E_OVERFLOW;
2099 *pbOut = (BYTE) fltIn;
2104 /******************************************************************************
2105 * VarUI1FromR8 [OLEAUT32.133]
2107 HRESULT WINAPI VarUI1FromR8(double dblIn, BYTE* pbOut)
2109 TRACE("( %f, %p ), stub\n", dblIn, pbOut );
2111 /* Check range of value.
2113 dblIn = round( dblIn );
2114 if( dblIn < UI1_MIN || dblIn > UI1_MAX )
2116 return DISP_E_OVERFLOW;
2119 *pbOut = (BYTE) dblIn;
2124 /******************************************************************************
2125 * VarUI1FromDate [OLEAUT32.135]
2127 HRESULT WINAPI VarUI1FromDate(DATE dateIn, BYTE* pbOut)
2129 TRACE("( %f, %p ), stub\n", dateIn, pbOut );
2131 /* Check range of value.
2133 dateIn = round( dateIn );
2134 if( dateIn < UI1_MIN || dateIn > UI1_MAX )
2136 return DISP_E_OVERFLOW;
2139 *pbOut = (BYTE) dateIn;
2144 /******************************************************************************
2145 * VarUI1FromBool [OLEAUT32.138]
2147 HRESULT WINAPI VarUI1FromBool(VARIANT_BOOL boolIn, BYTE* pbOut)
2149 TRACE("( %d, %p ), stub\n", boolIn, pbOut );
2151 *pbOut = (BYTE) boolIn;
2156 /******************************************************************************
2157 * VarUI1FromI1 [OLEAUT32.237]
2159 HRESULT WINAPI VarUI1FromI1(CHAR cIn, BYTE* pbOut)
2161 TRACE("( %c, %p ), stub\n", cIn, pbOut );
2168 /******************************************************************************
2169 * VarUI1FromUI2 [OLEAUT32.238]
2171 HRESULT WINAPI VarUI1FromUI2(USHORT uiIn, BYTE* pbOut)
2173 TRACE("( %d, %p ), stub\n", uiIn, pbOut );
2175 /* Check range of value.
2177 if( uiIn > UI1_MAX )
2179 return DISP_E_OVERFLOW;
2182 *pbOut = (BYTE) uiIn;
2187 /******************************************************************************
2188 * VarUI1FromUI4 [OLEAUT32.239]
2190 HRESULT WINAPI VarUI1FromUI4(ULONG ulIn, BYTE* pbOut)
2192 TRACE("( %ld, %p ), stub\n", ulIn, pbOut );
2194 /* Check range of value.
2196 if( ulIn > UI1_MAX )
2198 return DISP_E_OVERFLOW;
2201 *pbOut = (BYTE) ulIn;
2207 /******************************************************************************
2208 * VarUI1FromStr [OLEAUT32.136]
2210 HRESULT WINAPI VarUI1FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, BYTE* pbOut)
2212 double dValue = 0.0;
2213 LPSTR pNewString = NULL;
2215 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, pbOut );
2217 /* Check if we have a valid argument
2219 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2220 RemoveCharacterFromString( pNewString, "," );
2221 if( IsValidRealString( pNewString ) == FALSE )
2223 return DISP_E_TYPEMISMATCH;
2226 /* Convert the valid string to a floating point number.
2228 dValue = atof( pNewString );
2230 /* We don't need the string anymore so free it.
2232 HeapFree( GetProcessHeap(), 0 , pNewString );
2234 /* Check range of value.
2236 dValue = round( dValue );
2237 if( dValue < UI1_MIN || dValue > UI1_MAX )
2239 return DISP_E_OVERFLOW;
2242 *pbOut = (BYTE) dValue;
2247 /**********************************************************************
2248 * VarUI1FromCy [OLEAUT32.134]
2249 * Convert currency to unsigned char
2251 HRESULT WINAPI VarUI1FromCy(CY cyIn, BYTE* pbOut) {
2252 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2254 if (t > UI1_MAX || t < UI1_MIN) return DISP_E_OVERFLOW;
2260 /******************************************************************************
2261 * VarI2FromUI1 [OLEAUT32.48]
2263 HRESULT WINAPI VarI2FromUI1(BYTE bIn, short* psOut)
2265 TRACE("( 0x%08x, %p ), stub\n", bIn, psOut );
2267 *psOut = (short) bIn;
2272 /******************************************************************************
2273 * VarI2FromI4 [OLEAUT32.49]
2275 HRESULT WINAPI VarI2FromI4(LONG lIn, short* psOut)
2277 TRACE("( %lx, %p ), stub\n", lIn, psOut );
2279 /* Check range of value.
2281 if( lIn < I2_MIN || lIn > I2_MAX )
2283 return DISP_E_OVERFLOW;
2286 *psOut = (short) lIn;
2291 /******************************************************************************
2292 * VarI2FromR4 [OLEAUT32.50]
2294 HRESULT WINAPI VarI2FromR4(FLOAT fltIn, short* psOut)
2296 TRACE("( %f, %p ), stub\n", fltIn, psOut );
2298 /* Check range of value.
2300 fltIn = round( fltIn );
2301 if( fltIn < I2_MIN || fltIn > I2_MAX )
2303 return DISP_E_OVERFLOW;
2306 *psOut = (short) fltIn;
2311 /******************************************************************************
2312 * VarI2FromR8 [OLEAUT32.51]
2314 HRESULT WINAPI VarI2FromR8(double dblIn, short* psOut)
2316 TRACE("( %f, %p ), stub\n", dblIn, psOut );
2318 /* Check range of value.
2320 dblIn = round( dblIn );
2321 if( dblIn < I2_MIN || dblIn > I2_MAX )
2323 return DISP_E_OVERFLOW;
2326 *psOut = (short) dblIn;
2331 /******************************************************************************
2332 * VarI2FromDate [OLEAUT32.53]
2334 HRESULT WINAPI VarI2FromDate(DATE dateIn, short* psOut)
2336 TRACE("( %f, %p ), stub\n", dateIn, psOut );
2338 /* Check range of value.
2340 dateIn = round( dateIn );
2341 if( dateIn < I2_MIN || dateIn > I2_MAX )
2343 return DISP_E_OVERFLOW;
2346 *psOut = (short) dateIn;
2351 /******************************************************************************
2352 * VarI2FromBool [OLEAUT32.56]
2354 HRESULT WINAPI VarI2FromBool(VARIANT_BOOL boolIn, short* psOut)
2356 TRACE("( %d, %p ), stub\n", boolIn, psOut );
2358 *psOut = (short) boolIn;
2363 /******************************************************************************
2364 * VarI2FromI1 [OLEAUT32.205]
2366 HRESULT WINAPI VarI2FromI1(CHAR cIn, short* psOut)
2368 TRACE("( %c, %p ), stub\n", cIn, psOut );
2370 *psOut = (short) cIn;
2375 /******************************************************************************
2376 * VarI2FromUI2 [OLEAUT32.206]
2378 HRESULT WINAPI VarI2FromUI2(USHORT uiIn, short* psOut)
2380 TRACE("( %d, %p ), stub\n", uiIn, psOut );
2382 /* Check range of value.
2386 return DISP_E_OVERFLOW;
2389 *psOut = (short) uiIn;
2394 /******************************************************************************
2395 * VarI2FromUI4 [OLEAUT32.207]
2397 HRESULT WINAPI VarI2FromUI4(ULONG ulIn, short* psOut)
2399 TRACE("( %lx, %p ), stub\n", ulIn, psOut );
2401 /* Check range of value.
2403 if( ulIn < I2_MIN || ulIn > I2_MAX )
2405 return DISP_E_OVERFLOW;
2408 *psOut = (short) ulIn;
2413 /******************************************************************************
2414 * VarI2FromStr [OLEAUT32.54]
2416 HRESULT WINAPI VarI2FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, short* psOut)
2418 double dValue = 0.0;
2419 LPSTR pNewString = NULL;
2421 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, psOut );
2423 /* Check if we have a valid argument
2425 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2426 RemoveCharacterFromString( pNewString, "," );
2427 if( IsValidRealString( pNewString ) == FALSE )
2429 return DISP_E_TYPEMISMATCH;
2432 /* Convert the valid string to a floating point number.
2434 dValue = atof( pNewString );
2436 /* We don't need the string anymore so free it.
2438 HeapFree( GetProcessHeap(), 0, pNewString );
2440 /* Check range of value.
2442 dValue = round( dValue );
2443 if( dValue < I2_MIN || dValue > I2_MAX )
2445 return DISP_E_OVERFLOW;
2448 *psOut = (short) dValue;
2453 /**********************************************************************
2454 * VarI2FromCy [OLEAUT32.52]
2455 * Convert currency to signed short
2457 HRESULT WINAPI VarI2FromCy(CY cyIn, short* psOut) {
2458 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2460 if (t > I2_MAX || t < I2_MIN) return DISP_E_OVERFLOW;
2466 /******************************************************************************
2467 * VarI4FromUI1 [OLEAUT32.58]
2469 HRESULT WINAPI VarI4FromUI1(BYTE bIn, LONG* plOut)
2471 TRACE("( %X, %p ), stub\n", bIn, plOut );
2473 *plOut = (LONG) bIn;
2479 /******************************************************************************
2480 * VarI4FromR4 [OLEAUT32.60]
2482 HRESULT WINAPI VarI4FromR4(FLOAT fltIn, LONG* plOut)
2484 TRACE("( %f, %p ), stub\n", fltIn, plOut );
2486 /* Check range of value.
2488 fltIn = round( fltIn );
2489 if( fltIn < I4_MIN || fltIn > I4_MAX )
2491 return DISP_E_OVERFLOW;
2494 *plOut = (LONG) fltIn;
2499 /******************************************************************************
2500 * VarI4FromR8 [OLEAUT32.61]
2502 HRESULT WINAPI VarI4FromR8(double dblIn, LONG* plOut)
2504 TRACE("( %f, %p ), stub\n", dblIn, plOut );
2506 /* Check range of value.
2508 dblIn = round( dblIn );
2509 if( dblIn < I4_MIN || dblIn > I4_MAX )
2511 return DISP_E_OVERFLOW;
2514 *plOut = (LONG) dblIn;
2519 /******************************************************************************
2520 * VarI4FromDate [OLEAUT32.63]
2522 HRESULT WINAPI VarI4FromDate(DATE dateIn, LONG* plOut)
2524 TRACE("( %f, %p ), stub\n", dateIn, plOut );
2526 /* Check range of value.
2528 dateIn = round( dateIn );
2529 if( dateIn < I4_MIN || dateIn > I4_MAX )
2531 return DISP_E_OVERFLOW;
2534 *plOut = (LONG) dateIn;
2539 /******************************************************************************
2540 * VarI4FromBool [OLEAUT32.66]
2542 HRESULT WINAPI VarI4FromBool(VARIANT_BOOL boolIn, LONG* plOut)
2544 TRACE("( %d, %p ), stub\n", boolIn, plOut );
2546 *plOut = (LONG) boolIn;
2551 /******************************************************************************
2552 * VarI4FromI1 [OLEAUT32.209]
2554 HRESULT WINAPI VarI4FromI1(CHAR cIn, LONG* plOut)
2556 TRACE("( %c, %p ), stub\n", cIn, plOut );
2558 *plOut = (LONG) cIn;
2563 /******************************************************************************
2564 * VarI4FromUI2 [OLEAUT32.210]
2566 HRESULT WINAPI VarI4FromUI2(USHORT uiIn, LONG* plOut)
2568 TRACE("( %d, %p ), stub\n", uiIn, plOut );
2570 *plOut = (LONG) uiIn;
2575 /******************************************************************************
2576 * VarI4FromUI4 [OLEAUT32.211]
2578 HRESULT WINAPI VarI4FromUI4(ULONG ulIn, LONG* plOut)
2580 TRACE("( %lx, %p ), stub\n", ulIn, plOut );
2582 /* Check range of value.
2584 if( ulIn < I4_MIN || ulIn > I4_MAX )
2586 return DISP_E_OVERFLOW;
2589 *plOut = (LONG) ulIn;
2594 /******************************************************************************
2595 * VarI4FromI2 [OLEAUT32.59]
2597 HRESULT WINAPI VarI4FromI2(short sIn, LONG* plOut)
2599 TRACE("( %d, %p ), stub\n", sIn, plOut );
2601 *plOut = (LONG) sIn;
2606 /******************************************************************************
2607 * VarI4FromStr [OLEAUT32.64]
2609 HRESULT WINAPI VarI4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, LONG* plOut)
2611 double dValue = 0.0;
2612 LPSTR pNewString = NULL;
2614 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, plOut );
2616 /* Check if we have a valid argument
2618 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2619 RemoveCharacterFromString( pNewString, "," );
2620 if( IsValidRealString( pNewString ) == FALSE )
2622 return DISP_E_TYPEMISMATCH;
2625 /* Convert the valid string to a floating point number.
2627 dValue = atof( pNewString );
2629 /* We don't need the string anymore so free it.
2631 HeapFree( GetProcessHeap(), 0, pNewString );
2633 /* Check range of value.
2635 dValue = round( dValue );
2636 if( dValue < I4_MIN || dValue > I4_MAX )
2638 return DISP_E_OVERFLOW;
2641 *plOut = (LONG) dValue;
2646 /**********************************************************************
2647 * VarI4FromCy [OLEAUT32.62]
2648 * Convert currency to signed long
2650 HRESULT WINAPI VarI4FromCy(CY cyIn, LONG* plOut) {
2651 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2653 if (t > I4_MAX || t < I4_MIN) return DISP_E_OVERFLOW;
2659 /******************************************************************************
2660 * VarR4FromUI1 [OLEAUT32.68]
2662 HRESULT WINAPI VarR4FromUI1(BYTE bIn, FLOAT* pfltOut)
2664 TRACE("( %X, %p ), stub\n", bIn, pfltOut );
2666 *pfltOut = (FLOAT) bIn;
2671 /******************************************************************************
2672 * VarR4FromI2 [OLEAUT32.69]
2674 HRESULT WINAPI VarR4FromI2(short sIn, FLOAT* pfltOut)
2676 TRACE("( %d, %p ), stub\n", sIn, pfltOut );
2678 *pfltOut = (FLOAT) sIn;
2683 /******************************************************************************
2684 * VarR4FromI4 [OLEAUT32.70]
2686 HRESULT WINAPI VarR4FromI4(LONG lIn, FLOAT* pfltOut)
2688 TRACE("( %lx, %p ), stub\n", lIn, pfltOut );
2690 *pfltOut = (FLOAT) lIn;
2695 /******************************************************************************
2696 * VarR4FromR8 [OLEAUT32.71]
2698 HRESULT WINAPI VarR4FromR8(double dblIn, FLOAT* pfltOut)
2700 TRACE("( %f, %p ), stub\n", dblIn, pfltOut );
2702 /* Check range of value.
2704 if( dblIn < -(FLT_MAX) || dblIn > FLT_MAX )
2706 return DISP_E_OVERFLOW;
2709 *pfltOut = (FLOAT) dblIn;
2714 /******************************************************************************
2715 * VarR4FromDate [OLEAUT32.73]
2717 HRESULT WINAPI VarR4FromDate(DATE dateIn, FLOAT* pfltOut)
2719 TRACE("( %f, %p ), stub\n", dateIn, pfltOut );
2721 /* Check range of value.
2723 if( dateIn < -(FLT_MAX) || dateIn > FLT_MAX )
2725 return DISP_E_OVERFLOW;
2728 *pfltOut = (FLOAT) dateIn;
2733 /******************************************************************************
2734 * VarR4FromBool [OLEAUT32.76]
2736 HRESULT WINAPI VarR4FromBool(VARIANT_BOOL boolIn, FLOAT* pfltOut)
2738 TRACE("( %d, %p ), stub\n", boolIn, pfltOut );
2740 *pfltOut = (FLOAT) boolIn;
2745 /******************************************************************************
2746 * VarR4FromI1 [OLEAUT32.213]
2748 HRESULT WINAPI VarR4FromI1(CHAR cIn, FLOAT* pfltOut)
2750 TRACE("( %c, %p ), stub\n", cIn, pfltOut );
2752 *pfltOut = (FLOAT) cIn;
2757 /******************************************************************************
2758 * VarR4FromUI2 [OLEAUT32.214]
2760 HRESULT WINAPI VarR4FromUI2(USHORT uiIn, FLOAT* pfltOut)
2762 TRACE("( %d, %p ), stub\n", uiIn, pfltOut );
2764 *pfltOut = (FLOAT) uiIn;
2769 /******************************************************************************
2770 * VarR4FromUI4 [OLEAUT32.215]
2772 HRESULT WINAPI VarR4FromUI4(ULONG ulIn, FLOAT* pfltOut)
2774 TRACE("( %ld, %p ), stub\n", ulIn, pfltOut );
2776 *pfltOut = (FLOAT) ulIn;
2781 /******************************************************************************
2782 * VarR4FromStr [OLEAUT32.74]
2784 HRESULT WINAPI VarR4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, FLOAT* pfltOut)
2786 double dValue = 0.0;
2787 LPSTR pNewString = NULL;
2789 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pfltOut );
2791 /* Check if we have a valid argument
2793 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2794 RemoveCharacterFromString( pNewString, "," );
2795 if( IsValidRealString( pNewString ) == FALSE )
2797 return DISP_E_TYPEMISMATCH;
2800 /* Convert the valid string to a floating point number.
2802 dValue = atof( pNewString );
2804 /* We don't need the string anymore so free it.
2806 HeapFree( GetProcessHeap(), 0, pNewString );
2808 /* Check range of value.
2810 if( dValue < -(FLT_MAX) || dValue > FLT_MAX )
2812 return DISP_E_OVERFLOW;
2815 *pfltOut = (FLOAT) dValue;
2820 /**********************************************************************
2821 * VarR4FromCy [OLEAUT32.72]
2822 * Convert currency to float
2824 HRESULT WINAPI VarR4FromCy(CY cyIn, FLOAT* pfltOut) {
2825 *pfltOut = (FLOAT)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2830 /******************************************************************************
2831 * VarR8FromUI1 [OLEAUT32.78]
2833 HRESULT WINAPI VarR8FromUI1(BYTE bIn, double* pdblOut)
2835 TRACE("( %d, %p ), stub\n", bIn, pdblOut );
2837 *pdblOut = (double) bIn;
2842 /******************************************************************************
2843 * VarR8FromI2 [OLEAUT32.79]
2845 HRESULT WINAPI VarR8FromI2(short sIn, double* pdblOut)
2847 TRACE("( %d, %p ), stub\n", sIn, pdblOut );
2849 *pdblOut = (double) sIn;
2854 /******************************************************************************
2855 * VarR8FromI4 [OLEAUT32.80]
2857 HRESULT WINAPI VarR8FromI4(LONG lIn, double* pdblOut)
2859 TRACE("( %ld, %p ), stub\n", lIn, pdblOut );
2861 *pdblOut = (double) lIn;
2866 /******************************************************************************
2867 * VarR8FromR4 [OLEAUT32.81]
2869 HRESULT WINAPI VarR8FromR4(FLOAT fltIn, double* pdblOut)
2871 TRACE("( %f, %p ), stub\n", fltIn, pdblOut );
2873 *pdblOut = (double) fltIn;
2878 /******************************************************************************
2879 * VarR8FromDate [OLEAUT32.83]
2881 HRESULT WINAPI VarR8FromDate(DATE dateIn, double* pdblOut)
2883 TRACE("( %f, %p ), stub\n", dateIn, pdblOut );
2885 *pdblOut = (double) dateIn;
2890 /******************************************************************************
2891 * VarR8FromBool [OLEAUT32.86]
2893 HRESULT WINAPI VarR8FromBool(VARIANT_BOOL boolIn, double* pdblOut)
2895 TRACE("( %d, %p ), stub\n", boolIn, pdblOut );
2897 *pdblOut = (double) boolIn;
2902 /******************************************************************************
2903 * VarR8FromI1 [OLEAUT32.217]
2905 HRESULT WINAPI VarR8FromI1(CHAR cIn, double* pdblOut)
2907 TRACE("( %c, %p ), stub\n", cIn, pdblOut );
2909 *pdblOut = (double) cIn;
2914 /******************************************************************************
2915 * VarR8FromUI2 [OLEAUT32.218]
2917 HRESULT WINAPI VarR8FromUI2(USHORT uiIn, double* pdblOut)
2919 TRACE("( %d, %p ), stub\n", uiIn, pdblOut );
2921 *pdblOut = (double) uiIn;
2926 /******************************************************************************
2927 * VarR8FromUI4 [OLEAUT32.219]
2929 HRESULT WINAPI VarR8FromUI4(ULONG ulIn, double* pdblOut)
2931 TRACE("( %ld, %p ), stub\n", ulIn, pdblOut );
2933 *pdblOut = (double) ulIn;
2938 /******************************************************************************
2939 * VarR8FromStr [OLEAUT32.84]
2941 HRESULT WINAPI VarR8FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, double* pdblOut)
2943 double dValue = 0.0;
2944 LPSTR pNewString = NULL;
2946 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pdblOut );
2948 /* Check if we have a valid argument
2950 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2951 RemoveCharacterFromString( pNewString, "," );
2952 if( IsValidRealString( pNewString ) == FALSE )
2954 return DISP_E_TYPEMISMATCH;
2957 /* Convert the valid string to a floating point number.
2959 dValue = atof( pNewString );
2961 /* We don't need the string anymore so free it.
2963 HeapFree( GetProcessHeap(), 0, pNewString );
2970 /**********************************************************************
2971 * VarR8FromCy [OLEAUT32.82]
2972 * Convert currency to double
2974 HRESULT WINAPI VarR8FromCy(CY cyIn, double* pdblOut) {
2975 *pdblOut = (double)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2980 /******************************************************************************
2981 * VarDateFromUI1 [OLEAUT32.88]
2983 HRESULT WINAPI VarDateFromUI1(BYTE bIn, DATE* pdateOut)
2985 TRACE("( %d, %p ), stub\n", bIn, pdateOut );
2987 *pdateOut = (DATE) bIn;
2992 /******************************************************************************
2993 * VarDateFromI2 [OLEAUT32.89]
2995 HRESULT WINAPI VarDateFromI2(short sIn, DATE* pdateOut)
2997 TRACE("( %d, %p ), stub\n", sIn, pdateOut );
2999 *pdateOut = (DATE) sIn;
3004 /******************************************************************************
3005 * VarDateFromI4 [OLEAUT32.90]
3007 HRESULT WINAPI VarDateFromI4(LONG lIn, DATE* pdateOut)
3009 TRACE("( %ld, %p ), stub\n", lIn, pdateOut );
3011 if( lIn < DATE_MIN || lIn > DATE_MAX )
3013 return DISP_E_OVERFLOW;
3016 *pdateOut = (DATE) lIn;
3021 /******************************************************************************
3022 * VarDateFromR4 [OLEAUT32.91]
3024 HRESULT WINAPI VarDateFromR4(FLOAT fltIn, DATE* pdateOut)
3026 TRACE("( %f, %p ), stub\n", fltIn, pdateOut );
3028 if( ceil(fltIn) < DATE_MIN || floor(fltIn) > DATE_MAX )
3030 return DISP_E_OVERFLOW;
3033 *pdateOut = (DATE) fltIn;
3038 /******************************************************************************
3039 * VarDateFromR8 [OLEAUT32.92]
3041 HRESULT WINAPI VarDateFromR8(double dblIn, DATE* pdateOut)
3043 TRACE("( %f, %p ), stub\n", dblIn, pdateOut );
3045 if( ceil(dblIn) < DATE_MIN || floor(dblIn) > DATE_MAX )
3047 return DISP_E_OVERFLOW;
3050 *pdateOut = (DATE) dblIn;
3055 /******************************************************************************
3056 * VarDateFromStr [OLEAUT32.94]
3057 * The string representing the date is composed of two parts, a date and time.
3059 * The format of the time is has follows:
3060 * hh[:mm][:ss][AM|PM]
3061 * Whitespace can be inserted anywhere between these tokens. A whitespace consists
3062 * of space and/or tab characters, which are ignored.
3064 * The formats for the date part are has follows:
3068 * January dd[,] [yy]yy
3071 * Whitespace can be inserted anywhere between these tokens.
3073 * The formats for the date and time string are has follows.
3074 * date[whitespace][time]
3075 * [time][whitespace]date
3077 * These are the only characters allowed in a string representing a date and time:
3078 * [A-Z] [a-z] [0-9] ':' '-' '/' ',' ' ' '\t'
3080 HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pdateOut)
3085 memset( &TM, 0, sizeof(TM) );
3087 TRACE("( %p, %lx, %lx, %p ), stub\n", strIn, lcid, dwFlags, pdateOut );
3089 if( DateTimeStringToTm( strIn, dwFlags, &TM ) )
3091 if( TmToDATE( &TM, pdateOut ) == FALSE )
3098 ret = DISP_E_TYPEMISMATCH;
3105 /******************************************************************************
3106 * VarDateFromI1 [OLEAUT32.221]
3108 HRESULT WINAPI VarDateFromI1(CHAR cIn, DATE* pdateOut)
3110 TRACE("( %c, %p ), stub\n", cIn, pdateOut );
3112 *pdateOut = (DATE) cIn;
3117 /******************************************************************************
3118 * VarDateFromUI2 [OLEAUT32.222]
3120 HRESULT WINAPI VarDateFromUI2(USHORT uiIn, DATE* pdateOut)
3122 TRACE("( %d, %p ), stub\n", uiIn, pdateOut );
3124 if( uiIn > DATE_MAX )
3126 return DISP_E_OVERFLOW;
3129 *pdateOut = (DATE) uiIn;
3134 /******************************************************************************
3135 * VarDateFromUI4 [OLEAUT32.223]
3137 HRESULT WINAPI VarDateFromUI4(ULONG ulIn, DATE* pdateOut)
3139 TRACE("( %ld, %p ), stub\n", ulIn, pdateOut );
3141 if( ulIn < DATE_MIN || ulIn > DATE_MAX )
3143 return DISP_E_OVERFLOW;
3146 *pdateOut = (DATE) ulIn;
3151 /******************************************************************************
3152 * VarDateFromBool [OLEAUT32.96]
3154 HRESULT WINAPI VarDateFromBool(VARIANT_BOOL boolIn, DATE* pdateOut)
3156 TRACE("( %d, %p ), stub\n", boolIn, pdateOut );
3158 *pdateOut = (DATE) boolIn;
3163 /**********************************************************************
3164 * VarDateFromCy [OLEAUT32.93]
3165 * Convert currency to date
3167 HRESULT WINAPI VarDateFromCy(CY cyIn, DATE* pdateOut) {
3168 *pdateOut = (DATE)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3170 if (*pdateOut > DATE_MAX || *pdateOut < DATE_MIN) return DISP_E_TYPEMISMATCH;
3174 /******************************************************************************
3175 * VarBstrFromUI1 [OLEAUT32.108]
3177 HRESULT WINAPI VarBstrFromUI1(BYTE bVal, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3179 TRACE("( %d, %ld, %ld, %p ), stub\n", bVal, lcid, dwFlags, pbstrOut );
3180 sprintf( pBuffer, "%d", bVal );
3182 *pbstrOut = StringDupAtoBstr( pBuffer );
3187 /******************************************************************************
3188 * VarBstrFromI2 [OLEAUT32.109]
3190 HRESULT WINAPI VarBstrFromI2(short iVal, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3192 TRACE("( %d, %ld, %ld, %p ), stub\n", iVal, lcid, dwFlags, pbstrOut );
3193 sprintf( pBuffer, "%d", iVal );
3194 *pbstrOut = StringDupAtoBstr( pBuffer );
3199 /******************************************************************************
3200 * VarBstrFromI4 [OLEAUT32.110]
3202 HRESULT WINAPI VarBstrFromI4(LONG lIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3204 TRACE("( %ld, %ld, %ld, %p ), stub\n", lIn, lcid, dwFlags, pbstrOut );
3206 sprintf( pBuffer, "%ld", lIn );
3207 *pbstrOut = StringDupAtoBstr( pBuffer );
3212 /******************************************************************************
3213 * VarBstrFromR4 [OLEAUT32.111]
3215 HRESULT WINAPI VarBstrFromR4(FLOAT fltIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3217 TRACE("( %f, %ld, %ld, %p ), stub\n", fltIn, lcid, dwFlags, pbstrOut );
3219 sprintf( pBuffer, "%.7g", fltIn );
3220 *pbstrOut = StringDupAtoBstr( pBuffer );
3225 /******************************************************************************
3226 * VarBstrFromR8 [OLEAUT32.112]
3228 HRESULT WINAPI VarBstrFromR8(double dblIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3230 TRACE("( %f, %ld, %ld, %p ), stub\n", dblIn, lcid, dwFlags, pbstrOut );
3232 sprintf( pBuffer, "%.15g", dblIn );
3233 *pbstrOut = StringDupAtoBstr( pBuffer );
3238 /******************************************************************************
3239 * VarBstrFromCy [OLEAUT32.113]
3241 HRESULT WINAPI VarBstrFromCy(CY cyIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut) {
3242 FIXME("([cyIn], %08lx, %08lx, %p), stub.\n", lcid, dwFlags, pbstrOut);
3247 /******************************************************************************
3248 * VarBstrFromDate [OLEAUT32.114]
3250 * The date is implemented using an 8 byte floating-point number.
3251 * Days are represented by whole numbers increments starting with 0.00 as
3252 * being December 30 1899, midnight.
3253 * The hours are expressed as the fractional part of the number.
3254 * December 30 1899 at midnight = 0.00
3255 * January 1 1900 at midnight = 2.00
3256 * January 4 1900 at 6 AM = 5.25
3257 * January 4 1900 at noon = 5.50
3258 * December 29 1899 at midnight = -1.00
3259 * December 18 1899 at midnight = -12.00
3260 * December 18 1899 at 6AM = -12.25
3261 * December 18 1899 at 6PM = -12.75
3262 * December 19 1899 at midnight = -11.00
3263 * The tm structure is as follows:
3265 * int tm_sec; seconds after the minute - [0,59]
3266 * int tm_min; minutes after the hour - [0,59]
3267 * int tm_hour; hours since midnight - [0,23]
3268 * int tm_mday; day of the month - [1,31]
3269 * int tm_mon; months since January - [0,11]
3270 * int tm_year; years
3271 * int tm_wday; days since Sunday - [0,6]
3272 * int tm_yday; days since January 1 - [0,365]
3273 * int tm_isdst; daylight savings time flag
3276 HRESULT WINAPI VarBstrFromDate(DATE dateIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3279 memset( &TM, 0, sizeof(TM) );
3281 TRACE("( %f, %ld, %ld, %p ), stub\n", dateIn, lcid, dwFlags, pbstrOut );
3283 if( DateToTm( dateIn, dwFlags, &TM ) == FALSE )
3285 return E_INVALIDARG;
3288 if( dwFlags & VAR_DATEVALUEONLY )
3289 strftime( pBuffer, BUFFER_MAX, "%x", &TM );
3290 else if( dwFlags & VAR_TIMEVALUEONLY )
3291 strftime( pBuffer, BUFFER_MAX, "%X", &TM );
3293 strftime( pBuffer, BUFFER_MAX, "%x %X", &TM );
3295 *pbstrOut = StringDupAtoBstr( pBuffer );
3300 /******************************************************************************
3301 * VarBstrFromBool [OLEAUT32.116]
3303 HRESULT WINAPI VarBstrFromBool(VARIANT_BOOL boolIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3305 TRACE("( %d, %ld, %ld, %p ), stub\n", boolIn, lcid, dwFlags, pbstrOut );
3307 sprintf( pBuffer, (boolIn == VARIANT_FALSE) ? "False" : "True" );
3309 *pbstrOut = StringDupAtoBstr( pBuffer );
3314 /******************************************************************************
3315 * VarBstrFromI1 [OLEAUT32.229]
3317 HRESULT WINAPI VarBstrFromI1(CHAR cIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3319 TRACE("( %c, %ld, %ld, %p ), stub\n", cIn, lcid, dwFlags, pbstrOut );
3320 sprintf( pBuffer, "%d", cIn );
3321 *pbstrOut = StringDupAtoBstr( pBuffer );
3326 /******************************************************************************
3327 * VarBstrFromUI2 [OLEAUT32.230]
3329 HRESULT WINAPI VarBstrFromUI2(USHORT uiIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3331 TRACE("( %d, %ld, %ld, %p ), stub\n", uiIn, lcid, dwFlags, pbstrOut );
3332 sprintf( pBuffer, "%d", uiIn );
3333 *pbstrOut = StringDupAtoBstr( pBuffer );
3338 /******************************************************************************
3339 * VarBstrFromUI4 [OLEAUT32.231]
3341 HRESULT WINAPI VarBstrFromUI4(ULONG ulIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3343 TRACE("( %ld, %ld, %ld, %p ), stub\n", ulIn, lcid, dwFlags, pbstrOut );
3344 sprintf( pBuffer, "%ld", ulIn );
3345 *pbstrOut = StringDupAtoBstr( pBuffer );
3350 /******************************************************************************
3351 * VarBoolFromUI1 [OLEAUT32.118]
3353 HRESULT WINAPI VarBoolFromUI1(BYTE bIn, VARIANT_BOOL* pboolOut)
3355 TRACE("( %d, %p ), stub\n", bIn, pboolOut );
3359 *pboolOut = VARIANT_FALSE;
3363 *pboolOut = VARIANT_TRUE;
3369 /******************************************************************************
3370 * VarBoolFromI2 [OLEAUT32.119]
3372 HRESULT WINAPI VarBoolFromI2(short sIn, VARIANT_BOOL* pboolOut)
3374 TRACE("( %d, %p ), stub\n", sIn, pboolOut );
3376 *pboolOut = (sIn) ? VARIANT_TRUE : VARIANT_FALSE;
3381 /******************************************************************************
3382 * VarBoolFromI4 [OLEAUT32.120]
3384 HRESULT WINAPI VarBoolFromI4(LONG lIn, VARIANT_BOOL* pboolOut)
3386 TRACE("( %ld, %p ), stub\n", lIn, pboolOut );
3388 *pboolOut = (lIn) ? VARIANT_TRUE : VARIANT_FALSE;
3393 /******************************************************************************
3394 * VarBoolFromR4 [OLEAUT32.121]
3396 HRESULT WINAPI VarBoolFromR4(FLOAT fltIn, VARIANT_BOOL* pboolOut)
3398 TRACE("( %f, %p ), stub\n", fltIn, pboolOut );
3400 *pboolOut = (fltIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3405 /******************************************************************************
3406 * VarBoolFromR8 [OLEAUT32.122]
3408 HRESULT WINAPI VarBoolFromR8(double dblIn, VARIANT_BOOL* pboolOut)
3410 TRACE("( %f, %p ), stub\n", dblIn, pboolOut );
3412 *pboolOut = (dblIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3417 /******************************************************************************
3418 * VarBoolFromDate [OLEAUT32.123]
3420 HRESULT WINAPI VarBoolFromDate(DATE dateIn, VARIANT_BOOL* pboolOut)
3422 TRACE("( %f, %p ), stub\n", dateIn, pboolOut );
3424 *pboolOut = (dateIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3429 /******************************************************************************
3430 * VarBoolFromStr [OLEAUT32.125]
3432 HRESULT WINAPI VarBoolFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, VARIANT_BOOL* pboolOut)
3435 char* pNewString = NULL;
3437 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pboolOut );
3439 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3441 if( pNewString == NULL || strlen( pNewString ) == 0 )
3443 ret = DISP_E_TYPEMISMATCH;
3448 if( strncasecmp( pNewString, "True", strlen( pNewString ) ) == 0 )
3450 *pboolOut = VARIANT_TRUE;
3452 else if( strncasecmp( pNewString, "False", strlen( pNewString ) ) == 0 )
3454 *pboolOut = VARIANT_FALSE;
3458 /* Try converting the string to a floating point number.
3460 double dValue = 0.0;
3461 HRESULT res = VarR8FromStr( strIn, lcid, dwFlags, &dValue );
3464 ret = DISP_E_TYPEMISMATCH;
3467 *pboolOut = (dValue == 0.0) ?
3468 VARIANT_FALSE : VARIANT_TRUE;
3472 HeapFree( GetProcessHeap(), 0, pNewString );
3477 /******************************************************************************
3478 * VarBoolFromI1 [OLEAUT32.233]
3480 HRESULT WINAPI VarBoolFromI1(CHAR cIn, VARIANT_BOOL* pboolOut)
3482 TRACE("( %c, %p ), stub\n", cIn, pboolOut );
3484 *pboolOut = (cIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3489 /******************************************************************************
3490 * VarBoolFromUI2 [OLEAUT32.234]
3492 HRESULT WINAPI VarBoolFromUI2(USHORT uiIn, VARIANT_BOOL* pboolOut)
3494 TRACE("( %d, %p ), stub\n", uiIn, pboolOut );
3496 *pboolOut = (uiIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3501 /******************************************************************************
3502 * VarBoolFromUI4 [OLEAUT32.235]
3504 HRESULT WINAPI VarBoolFromUI4(ULONG ulIn, VARIANT_BOOL* pboolOut)
3506 TRACE("( %ld, %p ), stub\n", ulIn, pboolOut );
3508 *pboolOut = (ulIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3513 /**********************************************************************
3514 * VarBoolFromCy [OLEAUT32.124]
3515 * Convert currency to boolean
3517 HRESULT WINAPI VarBoolFromCy(CY cyIn, VARIANT_BOOL* pboolOut) {
3518 if (cyIn.s.Hi || cyIn.s.Lo) *pboolOut = -1;
3524 /******************************************************************************
3525 * VarI1FromUI1 [OLEAUT32.244]
3527 HRESULT WINAPI VarI1FromUI1(BYTE bIn, CHAR* pcOut)
3529 TRACE("( %d, %p ), stub\n", bIn, pcOut );
3531 /* Check range of value.
3533 if( bIn > CHAR_MAX )
3535 return DISP_E_OVERFLOW;
3538 *pcOut = (CHAR) bIn;
3543 /******************************************************************************
3544 * VarI1FromI2 [OLEAUT32.245]
3546 HRESULT WINAPI VarI1FromI2(short uiIn, CHAR* pcOut)
3548 TRACE("( %d, %p ), stub\n", uiIn, pcOut );
3550 if( uiIn > CHAR_MAX )
3552 return DISP_E_OVERFLOW;
3555 *pcOut = (CHAR) uiIn;
3560 /******************************************************************************
3561 * VarI1FromI4 [OLEAUT32.246]
3563 HRESULT WINAPI VarI1FromI4(LONG lIn, CHAR* pcOut)
3565 TRACE("( %ld, %p ), stub\n", lIn, pcOut );
3567 if( lIn < CHAR_MIN || lIn > CHAR_MAX )
3569 return DISP_E_OVERFLOW;
3572 *pcOut = (CHAR) lIn;
3577 /******************************************************************************
3578 * VarI1FromR4 [OLEAUT32.247]
3580 HRESULT WINAPI VarI1FromR4(FLOAT fltIn, CHAR* pcOut)
3582 TRACE("( %f, %p ), stub\n", fltIn, pcOut );
3584 fltIn = round( fltIn );
3585 if( fltIn < CHAR_MIN || fltIn > CHAR_MAX )
3587 return DISP_E_OVERFLOW;
3590 *pcOut = (CHAR) fltIn;
3595 /******************************************************************************
3596 * VarI1FromR8 [OLEAUT32.248]
3598 HRESULT WINAPI VarI1FromR8(double dblIn, CHAR* pcOut)
3600 TRACE("( %f, %p ), stub\n", dblIn, pcOut );
3602 dblIn = round( dblIn );
3603 if( dblIn < CHAR_MIN || dblIn > CHAR_MAX )
3605 return DISP_E_OVERFLOW;
3608 *pcOut = (CHAR) dblIn;
3613 /******************************************************************************
3614 * VarI1FromDate [OLEAUT32.249]
3616 HRESULT WINAPI VarI1FromDate(DATE dateIn, CHAR* pcOut)
3618 TRACE("( %f, %p ), stub\n", dateIn, pcOut );
3620 dateIn = round( dateIn );
3621 if( dateIn < CHAR_MIN || dateIn > CHAR_MAX )
3623 return DISP_E_OVERFLOW;
3626 *pcOut = (CHAR) dateIn;
3631 /******************************************************************************
3632 * VarI1FromStr [OLEAUT32.251]
3634 HRESULT WINAPI VarI1FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, CHAR* pcOut)
3636 double dValue = 0.0;
3637 LPSTR pNewString = NULL;
3639 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pcOut );
3641 /* Check if we have a valid argument
3643 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3644 RemoveCharacterFromString( pNewString, "," );
3645 if( IsValidRealString( pNewString ) == FALSE )
3647 return DISP_E_TYPEMISMATCH;
3650 /* Convert the valid string to a floating point number.
3652 dValue = atof( pNewString );
3654 /* We don't need the string anymore so free it.
3656 HeapFree( GetProcessHeap(), 0, pNewString );
3658 /* Check range of value.
3660 dValue = round( dValue );
3661 if( dValue < CHAR_MIN || dValue > CHAR_MAX )
3663 return DISP_E_OVERFLOW;
3666 *pcOut = (CHAR) dValue;
3671 /******************************************************************************
3672 * VarI1FromBool [OLEAUT32.253]
3674 HRESULT WINAPI VarI1FromBool(VARIANT_BOOL boolIn, CHAR* pcOut)
3676 TRACE("( %d, %p ), stub\n", boolIn, pcOut );
3678 *pcOut = (CHAR) boolIn;
3683 /******************************************************************************
3684 * VarI1FromUI2 [OLEAUT32.254]
3686 HRESULT WINAPI VarI1FromUI2(USHORT uiIn, CHAR* pcOut)
3688 TRACE("( %d, %p ), stub\n", uiIn, pcOut );
3690 if( uiIn > CHAR_MAX )
3692 return DISP_E_OVERFLOW;
3695 *pcOut = (CHAR) uiIn;
3700 /******************************************************************************
3701 * VarI1FromUI4 [OLEAUT32.255]
3703 HRESULT WINAPI VarI1FromUI4(ULONG ulIn, CHAR* pcOut)
3705 TRACE("( %ld, %p ), stub\n", ulIn, pcOut );
3707 if( ulIn > CHAR_MAX )
3709 return DISP_E_OVERFLOW;
3712 *pcOut = (CHAR) ulIn;
3717 /**********************************************************************
3718 * VarI1FromCy [OLEAUT32.250]
3719 * Convert currency to signed char
3721 HRESULT WINAPI VarI1FromCy(CY cyIn, CHAR* pcOut) {
3722 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3724 if (t > CHAR_MAX || t < CHAR_MIN) return DISP_E_OVERFLOW;
3730 /******************************************************************************
3731 * VarUI2FromUI1 [OLEAUT32.257]
3733 HRESULT WINAPI VarUI2FromUI1(BYTE bIn, USHORT* puiOut)
3735 TRACE("( %d, %p ), stub\n", bIn, puiOut );
3737 *puiOut = (USHORT) bIn;
3742 /******************************************************************************
3743 * VarUI2FromI2 [OLEAUT32.258]
3745 HRESULT WINAPI VarUI2FromI2(short uiIn, USHORT* puiOut)
3747 TRACE("( %d, %p ), stub\n", uiIn, puiOut );
3749 if( uiIn < UI2_MIN )
3751 return DISP_E_OVERFLOW;
3754 *puiOut = (USHORT) uiIn;
3759 /******************************************************************************
3760 * VarUI2FromI4 [OLEAUT32.259]
3762 HRESULT WINAPI VarUI2FromI4(LONG lIn, USHORT* puiOut)
3764 TRACE("( %ld, %p ), stub\n", lIn, puiOut );
3766 if( lIn < UI2_MIN || lIn > UI2_MAX )
3768 return DISP_E_OVERFLOW;
3771 *puiOut = (USHORT) lIn;
3776 /******************************************************************************
3777 * VarUI2FromR4 [OLEAUT32.260]
3779 HRESULT WINAPI VarUI2FromR4(FLOAT fltIn, USHORT* puiOut)
3781 TRACE("( %f, %p ), stub\n", fltIn, puiOut );
3783 fltIn = round( fltIn );
3784 if( fltIn < UI2_MIN || fltIn > UI2_MAX )
3786 return DISP_E_OVERFLOW;
3789 *puiOut = (USHORT) fltIn;
3794 /******************************************************************************
3795 * VarUI2FromR8 [OLEAUT32.261]
3797 HRESULT WINAPI VarUI2FromR8(double dblIn, USHORT* puiOut)
3799 TRACE("( %f, %p ), stub\n", dblIn, puiOut );
3801 dblIn = round( dblIn );
3802 if( dblIn < UI2_MIN || dblIn > UI2_MAX )
3804 return DISP_E_OVERFLOW;
3807 *puiOut = (USHORT) dblIn;
3812 /******************************************************************************
3813 * VarUI2FromDate [OLEAUT32.262]
3815 HRESULT WINAPI VarUI2FromDate(DATE dateIn, USHORT* puiOut)
3817 TRACE("( %f, %p ), stub\n", dateIn, puiOut );
3819 dateIn = round( dateIn );
3820 if( dateIn < UI2_MIN || dateIn > UI2_MAX )
3822 return DISP_E_OVERFLOW;
3825 *puiOut = (USHORT) dateIn;
3830 /******************************************************************************
3831 * VarUI2FromStr [OLEAUT32.264]
3833 HRESULT WINAPI VarUI2FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, USHORT* puiOut)
3835 double dValue = 0.0;
3836 LPSTR pNewString = NULL;
3838 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, puiOut );
3840 /* Check if we have a valid argument
3842 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3843 RemoveCharacterFromString( pNewString, "," );
3844 if( IsValidRealString( pNewString ) == FALSE )
3846 return DISP_E_TYPEMISMATCH;
3849 /* Convert the valid string to a floating point number.
3851 dValue = atof( pNewString );
3853 /* We don't need the string anymore so free it.
3855 HeapFree( GetProcessHeap(), 0, pNewString );
3857 /* Check range of value.
3859 dValue = round( dValue );
3860 if( dValue < UI2_MIN || dValue > UI2_MAX )
3862 return DISP_E_OVERFLOW;
3865 *puiOut = (USHORT) dValue;
3870 /******************************************************************************
3871 * VarUI2FromBool [OLEAUT32.266]
3873 HRESULT WINAPI VarUI2FromBool(VARIANT_BOOL boolIn, USHORT* puiOut)
3875 TRACE("( %d, %p ), stub\n", boolIn, puiOut );
3877 *puiOut = (USHORT) boolIn;
3882 /******************************************************************************
3883 * VarUI2FromI1 [OLEAUT32.267]
3885 HRESULT WINAPI VarUI2FromI1(CHAR cIn, USHORT* puiOut)
3887 TRACE("( %c, %p ), stub\n", cIn, puiOut );
3889 *puiOut = (USHORT) cIn;
3894 /******************************************************************************
3895 * VarUI2FromUI4 [OLEAUT32.268]
3897 HRESULT WINAPI VarUI2FromUI4(ULONG ulIn, USHORT* puiOut)
3899 TRACE("( %ld, %p ), stub\n", ulIn, puiOut );
3901 if( ulIn < UI2_MIN || ulIn > UI2_MAX )
3903 return DISP_E_OVERFLOW;
3906 *puiOut = (USHORT) ulIn;
3911 /******************************************************************************
3912 * VarUI4FromStr [OLEAUT32.277]
3914 HRESULT WINAPI VarUI4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, ULONG* pulOut)
3916 double dValue = 0.0;
3917 LPSTR pNewString = NULL;
3919 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pulOut );
3921 /* Check if we have a valid argument
3923 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3924 RemoveCharacterFromString( pNewString, "," );
3925 if( IsValidRealString( pNewString ) == FALSE )
3927 return DISP_E_TYPEMISMATCH;
3930 /* Convert the valid string to a floating point number.
3932 dValue = atof( pNewString );
3934 /* We don't need the string anymore so free it.
3936 HeapFree( GetProcessHeap(), 0, pNewString );
3938 /* Check range of value.
3940 dValue = round( dValue );
3941 if( dValue < UI4_MIN || dValue > UI4_MAX )
3943 return DISP_E_OVERFLOW;
3946 *pulOut = (ULONG) dValue;
3951 /**********************************************************************
3952 * VarUI2FromCy [OLEAUT32.263]
3953 * Convert currency to unsigned short
3955 HRESULT WINAPI VarUI2FromCy(CY cyIn, USHORT* pusOut) {
3956 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3958 if (t > UI2_MAX || t < UI2_MIN) return DISP_E_OVERFLOW;
3960 *pusOut = (USHORT)t;
3965 /******************************************************************************
3966 * VarUI4FromUI1 [OLEAUT32.270]
3968 HRESULT WINAPI VarUI4FromUI1(BYTE bIn, ULONG* pulOut)
3970 TRACE("( %d, %p ), stub\n", bIn, pulOut );
3972 *pulOut = (USHORT) bIn;
3977 /******************************************************************************
3978 * VarUI4FromI2 [OLEAUT32.271]
3980 HRESULT WINAPI VarUI4FromI2(short uiIn, ULONG* pulOut)
3982 TRACE("( %d, %p ), stub\n", uiIn, pulOut );
3984 if( uiIn < UI4_MIN )
3986 return DISP_E_OVERFLOW;
3989 *pulOut = (ULONG) uiIn;
3994 /******************************************************************************
3995 * VarUI4FromI4 [OLEAUT32.272]
3997 HRESULT WINAPI VarUI4FromI4(LONG lIn, ULONG* pulOut)
3999 TRACE("( %ld, %p ), stub\n", lIn, pulOut );
4003 return DISP_E_OVERFLOW;
4006 *pulOut = (ULONG) lIn;
4011 /******************************************************************************
4012 * VarUI4FromR4 [OLEAUT32.273]
4014 HRESULT WINAPI VarUI4FromR4(FLOAT fltIn, ULONG* pulOut)
4016 fltIn = round( fltIn );
4017 if( fltIn < UI4_MIN || fltIn > UI4_MAX )
4019 return DISP_E_OVERFLOW;
4022 *pulOut = (ULONG) fltIn;
4027 /******************************************************************************
4028 * VarUI4FromR8 [OLEAUT32.274]
4030 HRESULT WINAPI VarUI4FromR8(double dblIn, ULONG* pulOut)
4032 TRACE("( %f, %p ), stub\n", dblIn, pulOut );
4034 dblIn = round( dblIn );
4035 if( dblIn < UI4_MIN || dblIn > UI4_MAX )
4037 return DISP_E_OVERFLOW;
4040 *pulOut = (ULONG) dblIn;
4045 /******************************************************************************
4046 * VarUI4FromDate [OLEAUT32.275]
4048 HRESULT WINAPI VarUI4FromDate(DATE dateIn, ULONG* pulOut)
4050 TRACE("( %f, %p ), stub\n", dateIn, pulOut );
4052 dateIn = round( dateIn );
4053 if( dateIn < UI4_MIN || dateIn > UI4_MAX )
4055 return DISP_E_OVERFLOW;
4058 *pulOut = (ULONG) dateIn;
4063 /******************************************************************************
4064 * VarUI4FromBool [OLEAUT32.279]
4066 HRESULT WINAPI VarUI4FromBool(VARIANT_BOOL boolIn, ULONG* pulOut)
4068 TRACE("( %d, %p ), stub\n", boolIn, pulOut );
4070 *pulOut = (ULONG) boolIn;
4075 /******************************************************************************
4076 * VarUI4FromI1 [OLEAUT32.280]
4078 HRESULT WINAPI VarUI4FromI1(CHAR cIn, ULONG* pulOut)
4080 TRACE("( %c, %p ), stub\n", cIn, pulOut );
4082 *pulOut = (ULONG) cIn;
4087 /******************************************************************************
4088 * VarUI4FromUI2 [OLEAUT32.281]
4090 HRESULT WINAPI VarUI4FromUI2(USHORT uiIn, ULONG* pulOut)
4092 TRACE("( %d, %p ), stub\n", uiIn, pulOut );
4094 *pulOut = (ULONG) uiIn;
4099 /**********************************************************************
4100 * VarUI4FromCy [OLEAUT32.276]
4101 * Convert currency to unsigned long
4103 HRESULT WINAPI VarUI4FromCy(CY cyIn, ULONG* pulOut) {
4104 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
4106 if (t > UI4_MAX || t < UI4_MIN) return DISP_E_OVERFLOW;
4113 /**********************************************************************
4114 * VarCyFromUI1 [OLEAUT32.98]
4115 * Convert unsigned char to currency
4117 HRESULT WINAPI VarCyFromUI1(BYTE bIn, CY* pcyOut) {
4119 pcyOut->s.Lo = ((ULONG)bIn) * 10000;
4124 /**********************************************************************
4125 * VarCyFromI2 [OLEAUT32.99]
4126 * Convert signed short to currency
4128 HRESULT WINAPI VarCyFromI2(short sIn, CY* pcyOut) {
4129 if (sIn < 0) pcyOut->s.Hi = -1;
4130 else pcyOut->s.Hi = 0;
4131 pcyOut->s.Lo = ((ULONG)sIn) * 10000;
4136 /**********************************************************************
4137 * VarCyFromI4 [OLEAUT32.100]
4138 * Convert signed long to currency
4140 HRESULT WINAPI VarCyFromI4(LONG lIn, CY* pcyOut) {
4141 double t = (double)lIn * (double)10000;
4142 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4143 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4144 if (lIn < 0) pcyOut->s.Hi--;
4149 /**********************************************************************
4150 * VarCyFromR4 [OLEAUT32.101]
4151 * Convert float to currency
4153 HRESULT WINAPI VarCyFromR4(FLOAT fltIn, CY* pcyOut) {
4154 double t = round((double)fltIn * (double)10000);
4155 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4156 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4157 if (fltIn < 0) pcyOut->s.Hi--;
4162 /**********************************************************************
4163 * VarCyFromR8 [OLEAUT32.102]
4164 * Convert double to currency
4166 HRESULT WINAPI VarCyFromR8(double dblIn, CY* pcyOut) {
4167 double t = round(dblIn * (double)10000);
4168 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4169 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4170 if (dblIn < 0) pcyOut->s.Hi--;
4175 /**********************************************************************
4176 * VarCyFromDate [OLEAUT32.103]
4177 * Convert date to currency
4179 HRESULT WINAPI VarCyFromDate(DATE dateIn, CY* pcyOut) {
4180 double t = round((double)dateIn * (double)10000);
4181 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4182 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4183 if (dateIn < 0) pcyOut->s.Hi--;
4188 /**********************************************************************
4189 * VarCyFromStr [OLEAUT32.104]
4191 HRESULT WINAPI VarCyFromStr(OLECHAR *strIn, LCID lcid, ULONG dwFlags, CY *pcyOut) {
4192 FIXME("(%p, %08lx, %08lx, %p), stub.\n", strIn, lcid, dwFlags, pcyOut);
4197 /**********************************************************************
4198 * VarCyFromBool [OLEAUT32.106]
4199 * Convert boolean to currency
4201 HRESULT WINAPI VarCyFromBool(VARIANT_BOOL boolIn, CY* pcyOut) {
4202 if (boolIn < 0) pcyOut->s.Hi = -1;
4203 else pcyOut->s.Hi = 0;
4204 pcyOut->s.Lo = (ULONG)boolIn * (ULONG)10000;
4209 /**********************************************************************
4210 * VarCyFromI1 [OLEAUT32.225]
4211 * Convert signed char to currency
4213 HRESULT WINAPI VarCyFromI1(signed char cIn, CY* pcyOut) {
4214 if (cIn < 0) pcyOut->s.Hi = -1;
4215 else pcyOut->s.Hi = 0;
4216 pcyOut->s.Lo = (ULONG)cIn * (ULONG)10000;
4221 /**********************************************************************
4222 * VarCyFromUI2 [OLEAUT32.226]
4223 * Convert unsigned short to currency
4225 HRESULT WINAPI VarCyFromUI2(USHORT usIn, CY* pcyOut) {
4227 pcyOut->s.Lo = (ULONG)usIn * (ULONG)10000;
4232 /**********************************************************************
4233 * VarCyFromUI4 [OLEAUT32.227]
4234 * Convert unsigned long to currency
4236 HRESULT WINAPI VarCyFromUI4(ULONG ulIn, CY* pcyOut) {
4237 double t = (double)ulIn * (double)10000;
4238 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4239 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4245 /**********************************************************************
4246 * DosDateTimeToVariantTime [OLEAUT32.14]
4247 * Convert dos representation of time to the date and time representation
4248 * stored in a variant.
4250 INT WINAPI DosDateTimeToVariantTime(USHORT wDosDate, USHORT wDosTime,
4255 TRACE("( 0x%x, 0x%x, 0x%p ), stub\n", wDosDate, wDosTime, pvtime );
4257 t.tm_sec = (wDosTime & 0x001f) * 2;
4258 t.tm_min = (wDosTime & 0x07e0) >> 5;
4259 t.tm_hour = (wDosTime & 0xf800) >> 11;
4261 t.tm_mday = (wDosDate & 0x001f);
4262 t.tm_mon = (wDosDate & 0x01e0) >> 5;
4263 t.tm_year = ((wDosDate & 0xfe00) >> 9) + 1980;
4265 return TmToDATE( &t, pvtime );
4269 /**********************************************************************
4270 * VarParseNumFromStr [OLEAUT32.46]
4272 HRESULT WINAPI VarParseNumFromStr(OLECHAR * strIn, LCID lcid, ULONG dwFlags,
4273 NUMPARSE * pnumprs, BYTE * rgbDig)
4277 FIXME("(%s,flags=%lx,....), partial stub!\n",debugstr_w(strIn),dwFlags);
4278 FIXME("numparse: cDig=%d, InFlags=%lx\n",pnumprs->cDig,pnumprs->dwInFlags);
4280 /* The other struct components are to be set by us */
4282 memset(rgbDig,0,pnumprs->cDig);
4285 for (i=0; strIn[i] ;i++) {
4286 if ((strIn[i]>='0') && (strIn[i]<='9')) {
4287 if (pnumprs->cDig > cDig) {
4288 *(rgbDig++)=strIn[i]-'0';
4294 pnumprs->cDig = cDig;
4296 /* FIXME: Just patching some values in */
4297 pnumprs->nPwr10 = 0;
4298 pnumprs->nBaseShift = 0;
4299 pnumprs->cchUsed = lastent;
4300 pnumprs->dwOutFlags = NUMPRS_DECIMAL;
4305 /**********************************************************************
4306 * VarNumFromParseNum [OLEAUT32.47]
4308 HRESULT WINAPI VarNumFromParseNum(NUMPARSE * pnumprs, BYTE * rgbDig,
4309 ULONG dwVtBits, VARIANT * pvar)
4313 FIXME("(,dwVtBits=%lx,....), partial stub!\n",dwVtBits);
4316 for (i=0;i<pnumprs->cDig;i++)
4317 xint = xint*10 + rgbDig[i];
4320 if (dwVtBits & VTBIT_I4) {
4322 V_UNION(pvar,intVal) = xint;
4325 if (dwVtBits & VTBIT_R8) {
4327 V_UNION(pvar,dblVal) = xint;
4330 FIXME("vtbitmask is unsupported %lx\n",dwVtBits);
4336 /**********************************************************************
4337 * VariantTimeToDosDateTime [OLEAUT32.13]
4338 * Convert variant representation of time to the date and time representation
4341 INT WINAPI VariantTimeToDosDateTime(DATE pvtime, USHORT *wDosDate, USHORT *wDosTime)
4347 TRACE("( 0x%x, 0x%x, 0x%p ), stub\n", *wDosDate, *wDosTime, &pvtime );
4349 if (DateToTm(pvtime, 0, &t) < 0) return 0;
4351 *wDosTime = *wDosTime | (t.tm_sec / 2);
4352 *wDosTime = *wDosTime | (t.tm_min << 5);
4353 *wDosTime = *wDosTime | (t.tm_hour << 11);
4355 *wDosDate = *wDosDate | t.tm_mday ;
4356 *wDosDate = *wDosDate | t.tm_mon << 5;
4357 *wDosDate = *wDosDate | ((t.tm_year - 1980) << 9) ;
4363 /***********************************************************************
4364 * SystemTimeToVariantTime [OLEAUT32.184]
4366 HRESULT WINAPI SystemTimeToVariantTime( LPSYSTEMTIME lpSystemTime, double *pvtime )
4368 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4369 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4373 TRACE(" %d/%d/%d %d:%d:%d\n",
4374 lpSystemTime->wMonth, lpSystemTime->wDay,
4375 lpSystemTime->wYear, lpSystemTime->wHour,
4376 lpSystemTime->wMinute, lpSystemTime->wSecond);
4378 if (lpSystemTime->wYear >= 1900)
4380 t.tm_sec = lpSystemTime->wSecond;
4381 t.tm_min = lpSystemTime->wMinute;
4382 t.tm_hour = lpSystemTime->wHour;
4384 t.tm_mday = lpSystemTime->wDay;
4385 t.tm_mon = lpSystemTime->wMonth;
4386 t.tm_year = lpSystemTime->wYear;
4388 return TmToDATE( &t, pvtime );
4392 t.tm_sec = lpSystemTime->wSecond;
4393 t.tm_min = lpSystemTime->wMinute;
4394 t.tm_hour = lpSystemTime->wHour;
4396 if (isleap(lpSystemTime->wYear) )
4397 t.tm_mday = Days_Per_Month_LY[13 - lpSystemTime->wMonth] - lpSystemTime->wDay;
4399 t.tm_mday = Days_Per_Month[13 - lpSystemTime->wMonth] - lpSystemTime->wDay;
4401 t.tm_mon = 13 - lpSystemTime->wMonth;
4402 t.tm_year = 1900 + 1899 - lpSystemTime->wYear;
4404 TmToDATE( &t, pvtime );
4414 /***********************************************************************
4415 * VariantTimeToSystemTime [OLEAUT32.185]
4417 HRESULT WINAPI VariantTimeToSystemTime( double vtime, LPSYSTEMTIME lpSystemTime )
4419 double t = 0, timeofday = 0;
4421 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4422 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4424 /* The Month_Code is used to find the Day of the Week (LY = LeapYear)*/
4425 static const BYTE Month_Code[] = {0, 1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};
4426 static const BYTE Month_Code_LY[] = {0, 0, 3, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};
4428 /* The Century_Code is used to find the Day of the Week */
4429 static const BYTE Century_Code[] = {0, 6, 4, 2};
4433 TRACE(" Variant = %f SYSTEMTIME ptr %p", vtime, lpSystemTime);
4438 if (DateToTm(vtime, 0, &r ) <= 0) return 0;
4440 lpSystemTime->wSecond = r.tm_sec;
4441 lpSystemTime->wMinute = r.tm_min;
4442 lpSystemTime->wHour = r.tm_hour;
4443 lpSystemTime->wDay = r.tm_mday;
4444 lpSystemTime->wMonth = r.tm_mon;
4446 if (lpSystemTime->wMonth == 12)
4447 lpSystemTime->wMonth = 1;
4449 lpSystemTime->wMonth++;
4451 lpSystemTime->wYear = r.tm_year;
4457 if (DateToTm(vtime, 0, &r ) <= 0) return 0;
4459 lpSystemTime->wSecond = r.tm_sec;
4460 lpSystemTime->wMinute = r.tm_min;
4461 lpSystemTime->wHour = r.tm_hour;
4463 lpSystemTime->wMonth = 13 - r.tm_mon;
4465 if (lpSystemTime->wMonth == 1)
4466 lpSystemTime->wMonth = 12;
4468 lpSystemTime->wMonth--;
4470 lpSystemTime->wYear = 1899 - (r.tm_year - 1900);
4472 if (!isleap(lpSystemTime->wYear) )
4473 lpSystemTime->wDay = Days_Per_Month[13 - lpSystemTime->wMonth] - r.tm_mday;
4475 lpSystemTime->wDay = Days_Per_Month_LY[13 - lpSystemTime->wMonth] - r.tm_mday;
4480 if (!isleap(lpSystemTime->wYear))
4483 (Century_Code+Month_Code+Year_Code+Day) % 7
4485 The century code repeats every 400 years , so the array
4486 works out like this,
4488 Century_Code[0] is for 16th/20th Centry
4489 Century_Code[1] is for 17th/21th Centry
4490 Century_Code[2] is for 18th/22th Centry
4491 Century_Code[3] is for 19th/23th Centry
4493 The year code is found with the formula (year + (year / 4))
4494 the "year" must be between 0 and 99 .
4496 The Month Code (Month_Code[1]) starts with January and
4500 lpSystemTime->wDayOfWeek = (
4501 Century_Code[(( (lpSystemTime->wYear+100) - lpSystemTime->wYear%100) /100) %4]+
4502 ((lpSystemTime->wYear%100)+(lpSystemTime->wYear%100)/4)+
4503 Month_Code[lpSystemTime->wMonth]+
4504 lpSystemTime->wDay) % 7;
4506 if (lpSystemTime->wDayOfWeek == 0) lpSystemTime->wDayOfWeek = 7;
4507 else lpSystemTime->wDayOfWeek -= 1;
4511 lpSystemTime->wDayOfWeek = (
4512 Century_Code[(((lpSystemTime->wYear+100) - lpSystemTime->wYear%100)/100)%4]+
4513 ((lpSystemTime->wYear%100)+(lpSystemTime->wYear%100)/4)+
4514 Month_Code_LY[lpSystemTime->wMonth]+
4515 lpSystemTime->wDay) % 7;
4517 if (lpSystemTime->wDayOfWeek == 0) lpSystemTime->wDayOfWeek = 7;
4518 else lpSystemTime->wDayOfWeek -= 1;
4522 timeofday = vtime - t;
4524 lpSystemTime->wMilliseconds = (timeofday
4525 - lpSystemTime->wHour*(1/24)
4526 - lpSystemTime->wMinute*(1/1440)
4527 - lpSystemTime->wSecond*(1/86400) )*(1/5184000);
4532 /***********************************************************************
4533 * VarUdateFromDate [OLEAUT32.331]
4535 HRESULT WINAPI VarUdateFromDate( DATE datein, ULONG dwFlags, UDATE *pudateout)
4538 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4539 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4541 TRACE("DATE = %f\n", (double)datein);
4542 i = VariantTimeToSystemTime(datein, &(pudateout->st) );
4546 pudateout->wDayOfYear = 0;
4548 if (isleap(pudateout->st.wYear))
4550 for (i =1; i<pudateout->st.wMonth; i++)
4551 pudateout->wDayOfYear += Days_Per_Month[i];
4555 for (i =1; i<pudateout->st.wMonth; i++)
4556 pudateout->wDayOfYear += Days_Per_Month_LY[i];
4559 pudateout->wDayOfYear += pudateout->st.wDay;
4560 dwFlags = 0; /*VAR_VALIDDATE*/
4567 /***********************************************************************
4568 * VarDateFromUdate [OLEAUT32.330]
4570 HRESULT WINAPI VarDateFromUdate(UDATE *pudateout,
4571 ULONG dwFlags, DATE *datein)
4575 TRACE(" %d/%d/%d %d:%d:%d\n",
4576 pudateout->st.wMonth, pudateout->st.wDay,
4577 pudateout->st.wYear, pudateout->st.wHour,
4578 pudateout->st.wMinute, pudateout->st.wSecond);
4581 i = SystemTimeToVariantTime(&(pudateout->st), &t);
4584 if (i) dwFlags = 0; /*VAR_VALIDDATE*/
4591 /**********************************************************************
4592 * VarBstrCmp [OLEAUT32.440]
4595 * NORM_IGNORECASE, NORM_IGNORENONSPACE, NORM_IGNORESYMBOLS
4596 * NORM_IGNORESTRINGWIDTH, NORM_IGNOREKANATYPE, NORM_IGNOREKASHIDA
4599 HRESULT WINAPI VarBstrCmp(BSTR left, BSTR right, LCID lcid, DWORD flags)
4603 FIXME("( %s %s %ld %lx ) partial stub\n", debugstr_w(left), debugstr_w(right), lcid, flags);
4605 if((!left) || (!right))
4608 if(flags&NORM_IGNORECASE)
4609 r = lstrcmpiW(left,right);
4611 r = lstrcmpW(left,right);
4621 /**********************************************************************
4622 * VarBstrCat [OLEAUT32.439]
4624 HRESULT WINAPI VarBstrCat(BSTR left, BSTR right, BSTR *out)
4628 TRACE("( %s %s %p )\n", debugstr_w(left), debugstr_w(right), out);
4630 if( (!left) || (!right) || (!out) )
4633 result = SysAllocStringLen(left, lstrlenW(left)+lstrlenW(right));
4634 lstrcatW(result,right);