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 V_UNION(pd,lVal) = 0;
1025 res = VarI4FromI1( V_UNION(ps,cVal), &V_UNION(pd,lVal) );
1028 res = VarI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,lVal) );
1032 res = VariantCopy( pd, ps );
1035 res = VarI4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,lVal) );
1038 res = VarI4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,lVal) );
1042 res = VarI4FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,lVal) );
1045 res = VarI4FromR4( V_UNION(ps,fltVal), &V_UNION(pd,lVal) );
1048 res = VarI4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,lVal) );
1051 res = VarI4FromDate( V_UNION(ps,date), &V_UNION(pd,lVal) );
1054 res = VarI4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,lVal) );
1057 res = VarI4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,lVal) );
1060 res = VarI4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,lVal) );
1062 case( VT_DISPATCH ):
1063 /*res = VarI4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,lVal) );*/
1065 /*res = VarI4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,lVal) );*/
1068 res = DISP_E_TYPEMISMATCH;
1069 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1078 res = VarUI1FromI1( V_UNION(ps,cVal), &V_UNION(pd,bVal) );
1081 res = VarUI1FromI2( V_UNION(ps,iVal), &V_UNION(pd,bVal) );
1085 res = VarUI1FromI4( V_UNION(ps,lVal), &V_UNION(pd,bVal) );
1088 res = VariantCopy( pd, ps );
1091 res = VarUI1FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,bVal) );
1095 res = VarUI1FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,bVal) );
1098 res = VarUI1FromR4( V_UNION(ps,fltVal), &V_UNION(pd,bVal) );
1101 res = VarUI1FromR8( V_UNION(ps,dblVal), &V_UNION(pd,bVal) );
1104 res = VarUI1FromDate( V_UNION(ps,date), &V_UNION(pd,bVal) );
1107 res = VarUI1FromBool( V_UNION(ps,boolVal), &V_UNION(pd,bVal) );
1110 res = VarUI1FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,bVal) );
1113 res = VarUI1FromCy( V_UNION(ps,cyVal), &V_UNION(pd,bVal) );
1115 case( VT_DISPATCH ):
1116 /*res = VarUI1FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,bVal) );*/
1118 /*res = VarUI1FromDec( V_UNION(ps,deiVal), &V_UNION(pd,bVal) );*/
1121 res = DISP_E_TYPEMISMATCH;
1122 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1131 res = VarUI2FromI1( V_UNION(ps,cVal), &V_UNION(pd,uiVal) );
1134 res = VarUI2FromI2( V_UNION(ps,iVal), &V_UNION(pd,uiVal) );
1138 res = VarUI2FromI4( V_UNION(ps,lVal), &V_UNION(pd,uiVal) );
1141 res = VarUI2FromUI1( V_UNION(ps,bVal), &V_UNION(pd,uiVal) );
1144 res = VariantCopy( pd, ps );
1148 res = VarUI2FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,uiVal) );
1151 res = VarUI2FromR4( V_UNION(ps,fltVal), &V_UNION(pd,uiVal) );
1154 res = VarUI2FromR8( V_UNION(ps,dblVal), &V_UNION(pd,uiVal) );
1157 res = VarUI2FromDate( V_UNION(ps,date), &V_UNION(pd,uiVal) );
1160 res = VarUI2FromBool( V_UNION(ps,boolVal), &V_UNION(pd,uiVal) );
1163 res = VarUI2FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,uiVal) );
1166 res = VarUI2FromCy( V_UNION(ps,cyVal), &V_UNION(pd,uiVal) );
1168 case( VT_DISPATCH ):
1169 /*res = VarUI2FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,uiVal) );*/
1171 /*res = VarUI2FromDec( V_UNION(ps,deiVal), &V_UNION(pd,uiVal) );*/
1174 res = DISP_E_TYPEMISMATCH;
1175 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1185 res = VarUI4FromI1( V_UNION(ps,cVal), &V_UNION(pd,ulVal) );
1188 res = VarUI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,ulVal) );
1192 res = VarUI4FromI4( V_UNION(ps,lVal), &V_UNION(pd,ulVal) );
1195 res = VarUI4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,ulVal) );
1198 res = VarUI4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,ulVal) );
1201 res = VariantCopy( pd, ps );
1204 res = VarUI4FromR4( V_UNION(ps,fltVal), &V_UNION(pd,ulVal) );
1207 res = VarUI4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,ulVal) );
1210 res = VarUI4FromDate( V_UNION(ps,date), &V_UNION(pd,ulVal) );
1213 res = VarUI4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,ulVal) );
1216 res = VarUI4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,ulVal) );
1219 res = VarUI4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,ulVal) );
1221 case( VT_DISPATCH ):
1222 /*res = VarUI4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,ulVal) );*/
1224 /*res = VarUI4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,ulVal) );*/
1227 res = DISP_E_TYPEMISMATCH;
1228 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1237 res = VarR4FromI1( V_UNION(ps,cVal), &V_UNION(pd,fltVal) );
1240 res = VarR4FromI2( V_UNION(ps,iVal), &V_UNION(pd,fltVal) );
1244 res = VarR4FromI4( V_UNION(ps,lVal), &V_UNION(pd,fltVal) );
1247 res = VarR4FromUI1( V_UNION(ps,bVal), &V_UNION(pd,fltVal) );
1250 res = VarR4FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,fltVal) );
1254 res = VarR4FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,fltVal) );
1257 res = VariantCopy( pd, ps );
1260 res = VarR4FromR8( V_UNION(ps,dblVal), &V_UNION(pd,fltVal) );
1263 res = VarR4FromDate( V_UNION(ps,date), &V_UNION(pd,fltVal) );
1266 res = VarR4FromBool( V_UNION(ps,boolVal), &V_UNION(pd,fltVal) );
1269 res = VarR4FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,fltVal) );
1272 res = VarR4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,fltVal) );
1274 case( VT_DISPATCH ):
1275 /*res = VarR4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,fltVal) );*/
1277 /*res = VarR4FromDec( V_UNION(ps,deiVal), &V_UNION(pd,fltVal) );*/
1280 res = DISP_E_TYPEMISMATCH;
1281 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1290 res = VarR8FromI1( V_UNION(ps,cVal), &V_UNION(pd,dblVal) );
1293 res = VarR8FromI2( V_UNION(ps,iVal), &V_UNION(pd,dblVal) );
1297 res = VarR8FromI4( V_UNION(ps,lVal), &V_UNION(pd,dblVal) );
1300 res = VarR8FromUI1( V_UNION(ps,bVal), &V_UNION(pd,dblVal) );
1303 res = VarR8FromUI2( V_UNION(ps,uiVal), &V_UNION(pd,dblVal) );
1307 res = VarR8FromUI4( V_UNION(ps,ulVal), &V_UNION(pd,dblVal) );
1310 res = VarR8FromR4( V_UNION(ps,fltVal), &V_UNION(pd,dblVal) );
1313 res = VariantCopy( pd, ps );
1316 res = VarR8FromDate( V_UNION(ps,date), &V_UNION(pd,dblVal) );
1319 res = VarR8FromBool( V_UNION(ps,boolVal), &V_UNION(pd,dblVal) );
1322 res = VarR8FromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,dblVal) );
1325 res = VarR8FromCy( V_UNION(ps,cyVal), &V_UNION(pd,dblVal) );
1327 case( VT_DISPATCH ):
1328 /*res = VarR8FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,dblVal) );*/
1330 /*res = VarR8FromDec( V_UNION(ps,deiVal), &V_UNION(pd,dblVal) );*/
1333 res = DISP_E_TYPEMISMATCH;
1334 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1343 res = VarDateFromI1( V_UNION(ps,cVal), &V_UNION(pd,date) );
1346 res = VarDateFromI2( V_UNION(ps,iVal), &V_UNION(pd,date) );
1349 res = VarDateFromInt( V_UNION(ps,intVal), &V_UNION(pd,date) );
1352 res = VarDateFromI4( V_UNION(ps,lVal), &V_UNION(pd,date) );
1355 res = VarDateFromUI1( V_UNION(ps,bVal), &V_UNION(pd,date) );
1358 res = VarDateFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,date) );
1361 res = VarDateFromUint( V_UNION(ps,uintVal), &V_UNION(pd,date) );
1364 res = VarDateFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,date) );
1367 res = VarDateFromR4( V_UNION(ps,fltVal), &V_UNION(pd,date) );
1370 res = VarDateFromR8( V_UNION(ps,dblVal), &V_UNION(pd,date) );
1373 res = VariantCopy( pd, ps );
1376 res = VarDateFromBool( V_UNION(ps,boolVal), &V_UNION(pd,date) );
1379 res = VarDateFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,date) );
1382 res = VarDateFromCy( V_UNION(ps,cyVal), &V_UNION(pd,date) );
1384 case( VT_DISPATCH ):
1385 /*res = VarDateFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,date) );*/
1387 /*res = VarDateFromDec( V_UNION(ps,deiVal), &V_UNION(pd,date) );*/
1390 res = DISP_E_TYPEMISMATCH;
1391 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1400 res = VarBoolFromI1( V_UNION(ps,cVal), &V_UNION(pd,boolVal) );
1403 res = VarBoolFromI2( V_UNION(ps,iVal), &V_UNION(pd,boolVal) );
1406 res = VarBoolFromInt( V_UNION(ps,intVal), &V_UNION(pd,boolVal) );
1409 res = VarBoolFromI4( V_UNION(ps,lVal), &V_UNION(pd,boolVal) );
1412 res = VarBoolFromUI1( V_UNION(ps,bVal), &V_UNION(pd,boolVal) );
1415 res = VarBoolFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,boolVal) );
1418 res = VarBoolFromUint( V_UNION(ps,uintVal), &V_UNION(pd,boolVal) );
1421 res = VarBoolFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,boolVal) );
1424 res = VarBoolFromR4( V_UNION(ps,fltVal), &V_UNION(pd,boolVal) );
1427 res = VarBoolFromR8( V_UNION(ps,dblVal), &V_UNION(pd,boolVal) );
1430 res = VarBoolFromDate( V_UNION(ps,date), &V_UNION(pd,boolVal) );
1433 res = VariantCopy( pd, ps );
1436 res = VarBoolFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,boolVal) );
1439 res = VarBoolFromCy( V_UNION(ps,cyVal), &V_UNION(pd,boolVal) );
1441 case( VT_DISPATCH ):
1442 /*res = VarBoolFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,boolVal) );*/
1444 /*res = VarBoolFromDec( V_UNION(ps,deiVal), &V_UNION(pd,boolVal) );*/
1447 res = DISP_E_TYPEMISMATCH;
1448 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1457 if ((V_UNION(pd,bstrVal) = SysAllocStringLen(NULL, 0)))
1460 res = E_OUTOFMEMORY;
1463 res = VarBstrFromI1( V_UNION(ps,cVal), lcid, 0, &V_UNION(pd,bstrVal) );
1466 res = VarBstrFromI2( V_UNION(ps,iVal), lcid, 0, &V_UNION(pd,bstrVal) );
1469 res = VarBstrFromInt( V_UNION(ps,intVal), lcid, 0, &V_UNION(pd,bstrVal) );
1472 res = VarBstrFromI4( V_UNION(ps,lVal), lcid, 0, &V_UNION(pd,bstrVal) );
1475 res = VarBstrFromUI1( V_UNION(ps,bVal), lcid, 0, &V_UNION(pd,bstrVal) );
1478 res = VarBstrFromUI2( V_UNION(ps,uiVal), lcid, 0, &V_UNION(pd,bstrVal) );
1481 res = VarBstrFromUint( V_UNION(ps,uintVal), lcid, 0, &V_UNION(pd,bstrVal) );
1484 res = VarBstrFromUI4( V_UNION(ps,ulVal), lcid, 0, &V_UNION(pd,bstrVal) );
1487 res = VarBstrFromR4( V_UNION(ps,fltVal), lcid, 0, &V_UNION(pd,bstrVal) );
1490 res = VarBstrFromR8( V_UNION(ps,dblVal), lcid, 0, &V_UNION(pd,bstrVal) );
1493 res = VarBstrFromDate( V_UNION(ps,date), lcid, 0, &V_UNION(pd,bstrVal) );
1496 res = VarBstrFromBool( V_UNION(ps,boolVal), lcid, 0, &V_UNION(pd,bstrVal) );
1499 res = VariantCopy( pd, ps );
1502 res = VarBstrFromCy( V_UNION(ps,cyVal), lcid, 0, &V_UNION(pd,bstrVal) );
1504 case( VT_DISPATCH ):
1505 /*res = VarBstrFromDisp( V_UNION(ps,pdispVal), lcid, 0, &(pd,bstrVal) );*/
1507 /*res = VarBstrFromDec( V_UNION(ps,deiVal), lcid, 0, &(pd,bstrVal) );*/
1510 res = DISP_E_TYPEMISMATCH;
1511 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1520 res = VarCyFromI1( V_UNION(ps,cVal), &V_UNION(pd,cyVal) );
1523 res = VarCyFromI2( V_UNION(ps,iVal), &V_UNION(pd,cyVal) );
1526 res = VarCyFromInt( V_UNION(ps,intVal), &V_UNION(pd,cyVal) );
1529 res = VarCyFromI4( V_UNION(ps,lVal), &V_UNION(pd,cyVal) );
1532 res = VarCyFromUI1( V_UNION(ps,bVal), &V_UNION(pd,cyVal) );
1535 res = VarCyFromUI2( V_UNION(ps,uiVal), &V_UNION(pd,cyVal) );
1538 res = VarCyFromUint( V_UNION(ps,uintVal), &V_UNION(pd,cyVal) );
1541 res = VarCyFromUI4( V_UNION(ps,ulVal), &V_UNION(pd,cyVal) );
1544 res = VarCyFromR4( V_UNION(ps,fltVal), &V_UNION(pd,cyVal) );
1547 res = VarCyFromR8( V_UNION(ps,dblVal), &V_UNION(pd,cyVal) );
1550 res = VarCyFromDate( V_UNION(ps,date), &V_UNION(pd,cyVal) );
1553 res = VarCyFromBool( V_UNION(ps,date), &V_UNION(pd,cyVal) );
1556 res = VariantCopy( pd, ps );
1559 res = VarCyFromStr( V_UNION(ps,bstrVal), lcid, 0, &V_UNION(pd,cyVal) );
1561 case( VT_DISPATCH ):
1562 /*res = VarCyFromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,cyVal) );*/
1564 /*res = VarCyFromDec( V_UNION(ps,deiVal), &V_UNION(pd,cyVal) );*/
1568 res = DISP_E_TYPEMISMATCH;
1569 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1575 if (vtFrom == VT_DISPATCH)
1577 res = IDispatch_QueryInterface(V_DISPATCH(ps), &IID_IUnknown, (LPVOID*)&V_UNKNOWN(pd));
1581 res = DISP_E_TYPEMISMATCH;
1582 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1587 res = DISP_E_TYPEMISMATCH;
1588 FIXME("Coercion from %d to %d\n", vtFrom, vt );
1595 /******************************************************************************
1596 * ValidateVtRange [INTERNAL]
1598 * Used internally by the hi-level Variant API to determine
1599 * if the vartypes are valid.
1601 static HRESULT WINAPI ValidateVtRange( VARTYPE vt )
1603 /* if by value we must make sure it is in the
1604 * range of the valid types.
1606 if( ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1608 return DISP_E_BADVARTYPE;
1614 /******************************************************************************
1615 * ValidateVartype [INTERNAL]
1617 * Used internally by the hi-level Variant API to determine
1618 * if the vartypes are valid.
1620 static HRESULT WINAPI ValidateVariantType( VARTYPE vt )
1624 /* check if we have a valid argument.
1628 /* if by reference check that the type is in
1629 * the valid range and that it is not of empty or null type
1631 if( ( vt & VT_TYPEMASK ) == VT_EMPTY ||
1632 ( vt & VT_TYPEMASK ) == VT_NULL ||
1633 ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1641 res = ValidateVtRange( vt );
1647 /******************************************************************************
1648 * ValidateVt [INTERNAL]
1650 * Used internally by the hi-level Variant API to determine
1651 * if the vartypes are valid.
1653 static HRESULT WINAPI ValidateVt( VARTYPE vt )
1657 /* check if we have a valid argument.
1661 /* if by reference check that the type is in
1662 * the valid range and that it is not of empty or null type
1664 if( ( vt & VT_TYPEMASK ) == VT_EMPTY ||
1665 ( vt & VT_TYPEMASK ) == VT_NULL ||
1666 ( vt & VT_TYPEMASK ) > VT_MAXVALIDTYPE )
1668 res = DISP_E_BADVARTYPE;
1674 res = ValidateVtRange( vt );
1684 /******************************************************************************
1685 * VariantInit [OLEAUT32.8]
1687 * Initializes the Variant. Unlike VariantClear it does not interpret
1688 * the current contents of the Variant.
1690 void WINAPI VariantInit(VARIANTARG* pvarg)
1692 TRACE("(%p)\n",pvarg);
1694 memset(pvarg, 0, sizeof (VARIANTARG));
1695 V_VT(pvarg) = VT_EMPTY;
1700 /******************************************************************************
1701 * VariantClear [OLEAUT32.9]
1703 * This function clears the VARIANT by setting the vt field to VT_EMPTY. It also
1704 * sets the wReservedX field to 0. The current contents of the VARIANT are
1705 * freed. If the vt is VT_BSTR the string is freed. If VT_DISPATCH the object is
1706 * released. If VT_ARRAY the array is freed.
1708 HRESULT WINAPI VariantClear(VARIANTARG* pvarg)
1711 TRACE("(%p)\n",pvarg);
1713 res = ValidateVariantType( V_VT(pvarg) );
1716 if( !( V_VT(pvarg) & VT_BYREF ) )
1719 * The VT_ARRAY flag is a special case of a safe array.
1721 if ( (V_VT(pvarg) & VT_ARRAY) != 0)
1723 SafeArrayDestroy(V_UNION(pvarg,parray));
1727 switch( V_VT(pvarg) & VT_TYPEMASK )
1730 SysFreeString( V_UNION(pvarg,bstrVal) );
1732 case( VT_DISPATCH ):
1733 if(V_UNION(pvarg,pdispVal)!=NULL)
1734 ICOM_CALL(Release,V_UNION(pvarg,pdispVal));
1737 VariantClear(V_UNION(pvarg,pvarVal));
1740 if(V_UNION(pvarg,punkVal)!=NULL)
1741 ICOM_CALL(Release,V_UNION(pvarg,punkVal));
1743 case( VT_SAFEARRAY ):
1744 SafeArrayDestroy(V_UNION(pvarg,parray));
1753 * Empty all the fields and mark the type as empty.
1755 memset(pvarg, 0, sizeof (VARIANTARG));
1756 V_VT(pvarg) = VT_EMPTY;
1762 /******************************************************************************
1763 * VariantCopy [OLEAUT32.10]
1765 * Frees up the designation variant and makes a copy of the source.
1767 HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc)
1771 TRACE("(%p, %p), vt=%d\n", pvargDest, pvargSrc, V_VT(pvargSrc));
1773 res = ValidateVariantType( V_VT(pvargSrc) );
1775 /* If the pointer are to the same variant we don't need
1778 if( pvargDest != pvargSrc && res == S_OK )
1780 res = VariantClear( pvargDest );
1784 if( V_VT(pvargSrc) & VT_BYREF )
1786 /* In the case of byreference we only need
1787 * to copy the pointer.
1789 pvargDest->n1.n2.n3 = pvargSrc->n1.n2.n3;
1790 V_VT(pvargDest) = V_VT(pvargSrc);
1795 * The VT_ARRAY flag is another way to designate a safe array.
1797 if (V_VT(pvargSrc) & VT_ARRAY)
1799 SafeArrayCopy(V_UNION(pvargSrc,parray), &V_UNION(pvargDest,parray));
1803 /* In the case of by value we need to
1804 * copy the actual value. In the case of
1805 * VT_BSTR a copy of the string is made,
1806 * if VT_DISPATCH or VT_IUNKNOWN AddRef is
1807 * called to increment the object's reference count.
1809 switch( V_VT(pvargSrc) & VT_TYPEMASK )
1812 V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( V_UNION(pvargSrc,bstrVal) );
1814 case( VT_DISPATCH ):
1815 V_UNION(pvargDest,pdispVal) = V_UNION(pvargSrc,pdispVal);
1816 if (V_UNION(pvargDest,pdispVal)!=NULL)
1817 ICOM_CALL(AddRef,V_UNION(pvargDest,pdispVal));
1820 VariantCopy(V_UNION(pvargDest,pvarVal),V_UNION(pvargSrc,pvarVal));
1823 V_UNION(pvargDest,punkVal) = V_UNION(pvargSrc,punkVal);
1824 if (V_UNION(pvargDest,pdispVal)!=NULL)
1825 ICOM_CALL(AddRef,V_UNION(pvargDest,punkVal));
1827 case( VT_SAFEARRAY ):
1828 SafeArrayCopy(V_UNION(pvargSrc,parray), &V_UNION(pvargDest,parray));
1831 pvargDest->n1.n2.n3 = pvargSrc->n1.n2.n3;
1836 V_VT(pvargDest) = V_VT(pvargSrc);
1845 /******************************************************************************
1846 * VariantCopyInd [OLEAUT32.11]
1848 * Frees up the destination variant and makes a copy of the source. If
1849 * the source is of type VT_BYREF it performs the necessary indirections.
1851 HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc)
1855 TRACE("(%p, %p)\n", pvargDest, pvargSrc);
1857 res = ValidateVariantType( V_VT(pvargSrc) );
1862 if( V_VT(pvargSrc) & VT_BYREF )
1865 VariantInit( &varg );
1867 /* handle the in place copy.
1869 if( pvargDest == pvargSrc )
1871 /* we will use a copy of the source instead.
1873 res = VariantCopy( &varg, pvargSrc );
1879 res = VariantClear( pvargDest );
1884 * The VT_ARRAY flag is another way to designate a safearray variant.
1886 if ( V_VT(pvargSrc) & VT_ARRAY)
1888 SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
1892 /* In the case of by reference we need
1893 * to copy the date pointed to by the variant.
1896 /* Get the variant type.
1898 switch( V_VT(pvargSrc) & VT_TYPEMASK )
1901 V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( *(V_UNION(pvargSrc,pbstrVal)) );
1903 case( VT_DISPATCH ):
1907 /* Prevent from cycling. According to tests on
1908 * VariantCopyInd in Windows and the documentation
1909 * this API dereferences the inner Variants to only one depth.
1910 * If the inner Variant itself contains an
1911 * other inner variant the E_INVALIDARG error is
1914 if( pvargSrc->n1.n2.wReserved1 & PROCESSING_INNER_VARIANT )
1916 /* If we get here we are attempting to deference
1917 * an inner variant that that is itself contained
1918 * in an inner variant so report E_INVALIDARG error.
1924 /* Set the processing inner variant flag.
1925 * We will set this flag in the inner variant
1926 * that will be passed to the VariantCopyInd function.
1928 (V_UNION(pvargSrc,pvarVal))->n1.n2.wReserved1 |= PROCESSING_INNER_VARIANT;
1930 /* Dereference the inner variant.
1932 res = VariantCopyInd( pvargDest, V_UNION(pvargSrc,pvarVal) );
1933 /* We must also copy its type, I think.
1935 V_VT(pvargSrc) = V_VT(V_UNION(pvargSrc,pvarVal));
1941 case( VT_SAFEARRAY ):
1942 SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
1945 /* This is a by reference Variant which means that the union
1946 * part of the Variant contains a pointer to some data of
1947 * type "V_VT(pvargSrc) & VT_TYPEMASK".
1948 * We will deference this data in a generic fashion using
1949 * the void pointer "Variant.u.byref".
1950 * We will copy this data into the union of the destination
1953 memcpy( &pvargDest->n1.n2.n3, V_UNION(pvargSrc,byref), SizeOfVariantData( pvargSrc ) );
1958 V_VT(pvargDest) = V_VT(pvargSrc) & VT_TYPEMASK;
1962 /* this should not fail.
1964 VariantClear( &varg );
1968 res = VariantCopy( pvargDest, pvargSrc );
1974 /******************************************************************************
1975 * VariantChangeType [OLEAUT32.12]
1977 HRESULT WINAPI VariantChangeType(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
1978 USHORT wFlags, VARTYPE vt)
1980 return VariantChangeTypeEx( pvargDest, pvargSrc, 0, wFlags, vt );
1983 /******************************************************************************
1984 * VariantChangeTypeEx [OLEAUT32.147]
1986 HRESULT WINAPI VariantChangeTypeEx(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
1987 LCID lcid, USHORT wFlags, VARTYPE vt)
1991 VariantInit( &varg );
1993 TRACE("(%p, %p, %ld, %u, %u) vt=%d\n", pvargDest, pvargSrc, lcid, wFlags, vt, V_VT(pvargSrc));
1995 /* validate our source argument.
1997 res = ValidateVariantType( V_VT(pvargSrc) );
1999 /* validate the vartype.
2003 res = ValidateVt( vt );
2006 /* if we are doing an in-place conversion make a copy of the source.
2008 if( res == S_OK && pvargDest == pvargSrc )
2010 res = VariantCopy( &varg, pvargSrc );
2016 /* free up the destination variant.
2018 res = VariantClear( pvargDest );
2023 if( V_VT(pvargSrc) & VT_BYREF )
2025 /* Convert the source variant to a "byvalue" variant.
2028 VariantInit( &Variant );
2029 res = VariantCopyInd( &Variant, pvargSrc );
2032 res = Coerce( pvargDest, lcid, wFlags, &Variant, vt );
2033 /* this should not fail.
2035 VariantClear( &Variant );
2041 /* Use the current "byvalue" source variant.
2043 res = Coerce( pvargDest, lcid, wFlags, pvargSrc, vt );
2046 /* this should not fail.
2048 VariantClear( &varg );
2050 /* set the type of the destination
2053 V_VT(pvargDest) = vt;
2061 /******************************************************************************
2062 * VarUI1FromI2 [OLEAUT32.130]
2064 HRESULT WINAPI VarUI1FromI2(short sIn, BYTE* pbOut)
2066 TRACE("( %d, %p ), stub\n", sIn, pbOut );
2068 /* Check range of value.
2070 if( sIn < UI1_MIN || sIn > UI1_MAX )
2072 return DISP_E_OVERFLOW;
2075 *pbOut = (BYTE) sIn;
2080 /******************************************************************************
2081 * VarUI1FromI4 [OLEAUT32.131]
2083 HRESULT WINAPI VarUI1FromI4(LONG lIn, BYTE* pbOut)
2085 TRACE("( %ld, %p ), stub\n", lIn, pbOut );
2087 /* Check range of value.
2089 if( lIn < UI1_MIN || lIn > UI1_MAX )
2091 return DISP_E_OVERFLOW;
2094 *pbOut = (BYTE) lIn;
2100 /******************************************************************************
2101 * VarUI1FromR4 [OLEAUT32.132]
2103 HRESULT WINAPI VarUI1FromR4(FLOAT fltIn, BYTE* pbOut)
2105 TRACE("( %f, %p ), stub\n", fltIn, pbOut );
2107 /* Check range of value.
2109 fltIn = round( fltIn );
2110 if( fltIn < UI1_MIN || fltIn > UI1_MAX )
2112 return DISP_E_OVERFLOW;
2115 *pbOut = (BYTE) fltIn;
2120 /******************************************************************************
2121 * VarUI1FromR8 [OLEAUT32.133]
2123 HRESULT WINAPI VarUI1FromR8(double dblIn, BYTE* pbOut)
2125 TRACE("( %f, %p ), stub\n", dblIn, pbOut );
2127 /* Check range of value.
2129 dblIn = round( dblIn );
2130 if( dblIn < UI1_MIN || dblIn > UI1_MAX )
2132 return DISP_E_OVERFLOW;
2135 *pbOut = (BYTE) dblIn;
2140 /******************************************************************************
2141 * VarUI1FromDate [OLEAUT32.135]
2143 HRESULT WINAPI VarUI1FromDate(DATE dateIn, BYTE* pbOut)
2145 TRACE("( %f, %p ), stub\n", dateIn, pbOut );
2147 /* Check range of value.
2149 dateIn = round( dateIn );
2150 if( dateIn < UI1_MIN || dateIn > UI1_MAX )
2152 return DISP_E_OVERFLOW;
2155 *pbOut = (BYTE) dateIn;
2160 /******************************************************************************
2161 * VarUI1FromBool [OLEAUT32.138]
2163 HRESULT WINAPI VarUI1FromBool(VARIANT_BOOL boolIn, BYTE* pbOut)
2165 TRACE("( %d, %p ), stub\n", boolIn, pbOut );
2167 *pbOut = (BYTE) boolIn;
2172 /******************************************************************************
2173 * VarUI1FromI1 [OLEAUT32.237]
2175 HRESULT WINAPI VarUI1FromI1(CHAR cIn, BYTE* pbOut)
2177 TRACE("( %c, %p ), stub\n", cIn, pbOut );
2184 /******************************************************************************
2185 * VarUI1FromUI2 [OLEAUT32.238]
2187 HRESULT WINAPI VarUI1FromUI2(USHORT uiIn, BYTE* pbOut)
2189 TRACE("( %d, %p ), stub\n", uiIn, pbOut );
2191 /* Check range of value.
2193 if( uiIn > UI1_MAX )
2195 return DISP_E_OVERFLOW;
2198 *pbOut = (BYTE) uiIn;
2203 /******************************************************************************
2204 * VarUI1FromUI4 [OLEAUT32.239]
2206 HRESULT WINAPI VarUI1FromUI4(ULONG ulIn, BYTE* pbOut)
2208 TRACE("( %ld, %p ), stub\n", ulIn, pbOut );
2210 /* Check range of value.
2212 if( ulIn > UI1_MAX )
2214 return DISP_E_OVERFLOW;
2217 *pbOut = (BYTE) ulIn;
2223 /******************************************************************************
2224 * VarUI1FromStr [OLEAUT32.136]
2226 HRESULT WINAPI VarUI1FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, BYTE* pbOut)
2228 double dValue = 0.0;
2229 LPSTR pNewString = NULL;
2231 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, pbOut );
2233 /* Check if we have a valid argument
2235 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2236 RemoveCharacterFromString( pNewString, "," );
2237 if( IsValidRealString( pNewString ) == FALSE )
2239 return DISP_E_TYPEMISMATCH;
2242 /* Convert the valid string to a floating point number.
2244 dValue = atof( pNewString );
2246 /* We don't need the string anymore so free it.
2248 HeapFree( GetProcessHeap(), 0 , pNewString );
2250 /* Check range of value.
2252 dValue = round( dValue );
2253 if( dValue < UI1_MIN || dValue > UI1_MAX )
2255 return DISP_E_OVERFLOW;
2258 *pbOut = (BYTE) dValue;
2263 /**********************************************************************
2264 * VarUI1FromCy [OLEAUT32.134]
2265 * Convert currency to unsigned char
2267 HRESULT WINAPI VarUI1FromCy(CY cyIn, BYTE* pbOut) {
2268 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2270 if (t > UI1_MAX || t < UI1_MIN) return DISP_E_OVERFLOW;
2276 /******************************************************************************
2277 * VarI2FromUI1 [OLEAUT32.48]
2279 HRESULT WINAPI VarI2FromUI1(BYTE bIn, short* psOut)
2281 TRACE("( 0x%08x, %p ), stub\n", bIn, psOut );
2283 *psOut = (short) bIn;
2288 /******************************************************************************
2289 * VarI2FromI4 [OLEAUT32.49]
2291 HRESULT WINAPI VarI2FromI4(LONG lIn, short* psOut)
2293 TRACE("( %lx, %p ), stub\n", lIn, psOut );
2295 /* Check range of value.
2297 if( lIn < I2_MIN || lIn > I2_MAX )
2299 return DISP_E_OVERFLOW;
2302 *psOut = (short) lIn;
2307 /******************************************************************************
2308 * VarI2FromR4 [OLEAUT32.50]
2310 HRESULT WINAPI VarI2FromR4(FLOAT fltIn, short* psOut)
2312 TRACE("( %f, %p ), stub\n", fltIn, psOut );
2314 /* Check range of value.
2316 fltIn = round( fltIn );
2317 if( fltIn < I2_MIN || fltIn > I2_MAX )
2319 return DISP_E_OVERFLOW;
2322 *psOut = (short) fltIn;
2327 /******************************************************************************
2328 * VarI2FromR8 [OLEAUT32.51]
2330 HRESULT WINAPI VarI2FromR8(double dblIn, short* psOut)
2332 TRACE("( %f, %p ), stub\n", dblIn, psOut );
2334 /* Check range of value.
2336 dblIn = round( dblIn );
2337 if( dblIn < I2_MIN || dblIn > I2_MAX )
2339 return DISP_E_OVERFLOW;
2342 *psOut = (short) dblIn;
2347 /******************************************************************************
2348 * VarI2FromDate [OLEAUT32.53]
2350 HRESULT WINAPI VarI2FromDate(DATE dateIn, short* psOut)
2352 TRACE("( %f, %p ), stub\n", dateIn, psOut );
2354 /* Check range of value.
2356 dateIn = round( dateIn );
2357 if( dateIn < I2_MIN || dateIn > I2_MAX )
2359 return DISP_E_OVERFLOW;
2362 *psOut = (short) dateIn;
2367 /******************************************************************************
2368 * VarI2FromBool [OLEAUT32.56]
2370 HRESULT WINAPI VarI2FromBool(VARIANT_BOOL boolIn, short* psOut)
2372 TRACE("( %d, %p ), stub\n", boolIn, psOut );
2374 *psOut = (short) boolIn;
2379 /******************************************************************************
2380 * VarI2FromI1 [OLEAUT32.205]
2382 HRESULT WINAPI VarI2FromI1(CHAR cIn, short* psOut)
2384 TRACE("( %c, %p ), stub\n", cIn, psOut );
2386 *psOut = (short) cIn;
2391 /******************************************************************************
2392 * VarI2FromUI2 [OLEAUT32.206]
2394 HRESULT WINAPI VarI2FromUI2(USHORT uiIn, short* psOut)
2396 TRACE("( %d, %p ), stub\n", uiIn, psOut );
2398 /* Check range of value.
2402 return DISP_E_OVERFLOW;
2405 *psOut = (short) uiIn;
2410 /******************************************************************************
2411 * VarI2FromUI4 [OLEAUT32.207]
2413 HRESULT WINAPI VarI2FromUI4(ULONG ulIn, short* psOut)
2415 TRACE("( %lx, %p ), stub\n", ulIn, psOut );
2417 /* Check range of value.
2419 if( ulIn < I2_MIN || ulIn > I2_MAX )
2421 return DISP_E_OVERFLOW;
2424 *psOut = (short) ulIn;
2429 /******************************************************************************
2430 * VarI2FromStr [OLEAUT32.54]
2432 HRESULT WINAPI VarI2FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, short* psOut)
2434 double dValue = 0.0;
2435 LPSTR pNewString = NULL;
2437 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, psOut );
2439 /* Check if we have a valid argument
2441 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2442 RemoveCharacterFromString( pNewString, "," );
2443 if( IsValidRealString( pNewString ) == FALSE )
2445 return DISP_E_TYPEMISMATCH;
2448 /* Convert the valid string to a floating point number.
2450 dValue = atof( pNewString );
2452 /* We don't need the string anymore so free it.
2454 HeapFree( GetProcessHeap(), 0, pNewString );
2456 /* Check range of value.
2458 dValue = round( dValue );
2459 if( dValue < I2_MIN || dValue > I2_MAX )
2461 return DISP_E_OVERFLOW;
2464 *psOut = (short) dValue;
2469 /**********************************************************************
2470 * VarI2FromCy [OLEAUT32.52]
2471 * Convert currency to signed short
2473 HRESULT WINAPI VarI2FromCy(CY cyIn, short* psOut) {
2474 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2476 if (t > I2_MAX || t < I2_MIN) return DISP_E_OVERFLOW;
2482 /******************************************************************************
2483 * VarI4FromUI1 [OLEAUT32.58]
2485 HRESULT WINAPI VarI4FromUI1(BYTE bIn, LONG* plOut)
2487 TRACE("( %X, %p ), stub\n", bIn, plOut );
2489 *plOut = (LONG) bIn;
2495 /******************************************************************************
2496 * VarI4FromR4 [OLEAUT32.60]
2498 HRESULT WINAPI VarI4FromR4(FLOAT fltIn, LONG* plOut)
2500 TRACE("( %f, %p ), stub\n", fltIn, plOut );
2502 /* Check range of value.
2504 fltIn = round( fltIn );
2505 if( fltIn < I4_MIN || fltIn > I4_MAX )
2507 return DISP_E_OVERFLOW;
2510 *plOut = (LONG) fltIn;
2515 /******************************************************************************
2516 * VarI4FromR8 [OLEAUT32.61]
2518 HRESULT WINAPI VarI4FromR8(double dblIn, LONG* plOut)
2520 TRACE("( %f, %p ), stub\n", dblIn, plOut );
2522 /* Check range of value.
2524 dblIn = round( dblIn );
2525 if( dblIn < I4_MIN || dblIn > I4_MAX )
2527 return DISP_E_OVERFLOW;
2530 *plOut = (LONG) dblIn;
2535 /******************************************************************************
2536 * VarI4FromDate [OLEAUT32.63]
2538 HRESULT WINAPI VarI4FromDate(DATE dateIn, LONG* plOut)
2540 TRACE("( %f, %p ), stub\n", dateIn, plOut );
2542 /* Check range of value.
2544 dateIn = round( dateIn );
2545 if( dateIn < I4_MIN || dateIn > I4_MAX )
2547 return DISP_E_OVERFLOW;
2550 *plOut = (LONG) dateIn;
2555 /******************************************************************************
2556 * VarI4FromBool [OLEAUT32.66]
2558 HRESULT WINAPI VarI4FromBool(VARIANT_BOOL boolIn, LONG* plOut)
2560 TRACE("( %d, %p ), stub\n", boolIn, plOut );
2562 *plOut = (LONG) boolIn;
2567 /******************************************************************************
2568 * VarI4FromI1 [OLEAUT32.209]
2570 HRESULT WINAPI VarI4FromI1(CHAR cIn, LONG* plOut)
2572 TRACE("( %c, %p ), stub\n", cIn, plOut );
2574 *plOut = (LONG) cIn;
2579 /******************************************************************************
2580 * VarI4FromUI2 [OLEAUT32.210]
2582 HRESULT WINAPI VarI4FromUI2(USHORT uiIn, LONG* plOut)
2584 TRACE("( %d, %p ), stub\n", uiIn, plOut );
2586 *plOut = (LONG) uiIn;
2591 /******************************************************************************
2592 * VarI4FromUI4 [OLEAUT32.211]
2594 HRESULT WINAPI VarI4FromUI4(ULONG ulIn, LONG* plOut)
2596 TRACE("( %lx, %p ), stub\n", ulIn, plOut );
2598 /* Check range of value.
2600 if( ulIn < I4_MIN || ulIn > I4_MAX )
2602 return DISP_E_OVERFLOW;
2605 *plOut = (LONG) ulIn;
2610 /******************************************************************************
2611 * VarI4FromI2 [OLEAUT32.59]
2613 HRESULT WINAPI VarI4FromI2(short sIn, LONG* plOut)
2615 TRACE("( %d, %p ), stub\n", sIn, plOut );
2617 *plOut = (LONG) sIn;
2622 /******************************************************************************
2623 * VarI4FromStr [OLEAUT32.64]
2625 HRESULT WINAPI VarI4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, LONG* plOut)
2627 double dValue = 0.0;
2628 LPSTR pNewString = NULL;
2630 TRACE("( %p, 0x%08lx, 0x%08lx, %p ), stub\n", strIn, lcid, dwFlags, plOut );
2632 /* Check if we have a valid argument
2634 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2635 RemoveCharacterFromString( pNewString, "," );
2636 if( IsValidRealString( pNewString ) == FALSE )
2638 return DISP_E_TYPEMISMATCH;
2641 /* Convert the valid string to a floating point number.
2643 dValue = atof( pNewString );
2645 /* We don't need the string anymore so free it.
2647 HeapFree( GetProcessHeap(), 0, pNewString );
2649 /* Check range of value.
2651 dValue = round( dValue );
2652 if( dValue < I4_MIN || dValue > I4_MAX )
2654 return DISP_E_OVERFLOW;
2657 *plOut = (LONG) dValue;
2662 /**********************************************************************
2663 * VarI4FromCy [OLEAUT32.62]
2664 * Convert currency to signed long
2666 HRESULT WINAPI VarI4FromCy(CY cyIn, LONG* plOut) {
2667 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2669 if (t > I4_MAX || t < I4_MIN) return DISP_E_OVERFLOW;
2675 /******************************************************************************
2676 * VarR4FromUI1 [OLEAUT32.68]
2678 HRESULT WINAPI VarR4FromUI1(BYTE bIn, FLOAT* pfltOut)
2680 TRACE("( %X, %p ), stub\n", bIn, pfltOut );
2682 *pfltOut = (FLOAT) bIn;
2687 /******************************************************************************
2688 * VarR4FromI2 [OLEAUT32.69]
2690 HRESULT WINAPI VarR4FromI2(short sIn, FLOAT* pfltOut)
2692 TRACE("( %d, %p ), stub\n", sIn, pfltOut );
2694 *pfltOut = (FLOAT) sIn;
2699 /******************************************************************************
2700 * VarR4FromI4 [OLEAUT32.70]
2702 HRESULT WINAPI VarR4FromI4(LONG lIn, FLOAT* pfltOut)
2704 TRACE("( %lx, %p ), stub\n", lIn, pfltOut );
2706 *pfltOut = (FLOAT) lIn;
2711 /******************************************************************************
2712 * VarR4FromR8 [OLEAUT32.71]
2714 HRESULT WINAPI VarR4FromR8(double dblIn, FLOAT* pfltOut)
2716 TRACE("( %f, %p ), stub\n", dblIn, pfltOut );
2718 /* Check range of value.
2720 if( dblIn < -(FLT_MAX) || dblIn > FLT_MAX )
2722 return DISP_E_OVERFLOW;
2725 *pfltOut = (FLOAT) dblIn;
2730 /******************************************************************************
2731 * VarR4FromDate [OLEAUT32.73]
2733 HRESULT WINAPI VarR4FromDate(DATE dateIn, FLOAT* pfltOut)
2735 TRACE("( %f, %p ), stub\n", dateIn, pfltOut );
2737 /* Check range of value.
2739 if( dateIn < -(FLT_MAX) || dateIn > FLT_MAX )
2741 return DISP_E_OVERFLOW;
2744 *pfltOut = (FLOAT) dateIn;
2749 /******************************************************************************
2750 * VarR4FromBool [OLEAUT32.76]
2752 HRESULT WINAPI VarR4FromBool(VARIANT_BOOL boolIn, FLOAT* pfltOut)
2754 TRACE("( %d, %p ), stub\n", boolIn, pfltOut );
2756 *pfltOut = (FLOAT) boolIn;
2761 /******************************************************************************
2762 * VarR4FromI1 [OLEAUT32.213]
2764 HRESULT WINAPI VarR4FromI1(CHAR cIn, FLOAT* pfltOut)
2766 TRACE("( %c, %p ), stub\n", cIn, pfltOut );
2768 *pfltOut = (FLOAT) cIn;
2773 /******************************************************************************
2774 * VarR4FromUI2 [OLEAUT32.214]
2776 HRESULT WINAPI VarR4FromUI2(USHORT uiIn, FLOAT* pfltOut)
2778 TRACE("( %d, %p ), stub\n", uiIn, pfltOut );
2780 *pfltOut = (FLOAT) uiIn;
2785 /******************************************************************************
2786 * VarR4FromUI4 [OLEAUT32.215]
2788 HRESULT WINAPI VarR4FromUI4(ULONG ulIn, FLOAT* pfltOut)
2790 TRACE("( %ld, %p ), stub\n", ulIn, pfltOut );
2792 *pfltOut = (FLOAT) ulIn;
2797 /******************************************************************************
2798 * VarR4FromStr [OLEAUT32.74]
2800 HRESULT WINAPI VarR4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, FLOAT* pfltOut)
2802 double dValue = 0.0;
2803 LPSTR pNewString = NULL;
2805 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pfltOut );
2807 /* Check if we have a valid argument
2809 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2810 RemoveCharacterFromString( pNewString, "," );
2811 if( IsValidRealString( pNewString ) == FALSE )
2813 return DISP_E_TYPEMISMATCH;
2816 /* Convert the valid string to a floating point number.
2818 dValue = atof( pNewString );
2820 /* We don't need the string anymore so free it.
2822 HeapFree( GetProcessHeap(), 0, pNewString );
2824 /* Check range of value.
2826 if( dValue < -(FLT_MAX) || dValue > FLT_MAX )
2828 return DISP_E_OVERFLOW;
2831 *pfltOut = (FLOAT) dValue;
2836 /**********************************************************************
2837 * VarR4FromCy [OLEAUT32.72]
2838 * Convert currency to float
2840 HRESULT WINAPI VarR4FromCy(CY cyIn, FLOAT* pfltOut) {
2841 *pfltOut = (FLOAT)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2846 /******************************************************************************
2847 * VarR8FromUI1 [OLEAUT32.78]
2849 HRESULT WINAPI VarR8FromUI1(BYTE bIn, double* pdblOut)
2851 TRACE("( %d, %p ), stub\n", bIn, pdblOut );
2853 *pdblOut = (double) bIn;
2858 /******************************************************************************
2859 * VarR8FromI2 [OLEAUT32.79]
2861 HRESULT WINAPI VarR8FromI2(short sIn, double* pdblOut)
2863 TRACE("( %d, %p ), stub\n", sIn, pdblOut );
2865 *pdblOut = (double) sIn;
2870 /******************************************************************************
2871 * VarR8FromI4 [OLEAUT32.80]
2873 HRESULT WINAPI VarR8FromI4(LONG lIn, double* pdblOut)
2875 TRACE("( %ld, %p ), stub\n", lIn, pdblOut );
2877 *pdblOut = (double) lIn;
2882 /******************************************************************************
2883 * VarR8FromR4 [OLEAUT32.81]
2885 HRESULT WINAPI VarR8FromR4(FLOAT fltIn, double* pdblOut)
2887 TRACE("( %f, %p ), stub\n", fltIn, pdblOut );
2889 *pdblOut = (double) fltIn;
2894 /******************************************************************************
2895 * VarR8FromDate [OLEAUT32.83]
2897 HRESULT WINAPI VarR8FromDate(DATE dateIn, double* pdblOut)
2899 TRACE("( %f, %p ), stub\n", dateIn, pdblOut );
2901 *pdblOut = (double) dateIn;
2906 /******************************************************************************
2907 * VarR8FromBool [OLEAUT32.86]
2909 HRESULT WINAPI VarR8FromBool(VARIANT_BOOL boolIn, double* pdblOut)
2911 TRACE("( %d, %p ), stub\n", boolIn, pdblOut );
2913 *pdblOut = (double) boolIn;
2918 /******************************************************************************
2919 * VarR8FromI1 [OLEAUT32.217]
2921 HRESULT WINAPI VarR8FromI1(CHAR cIn, double* pdblOut)
2923 TRACE("( %c, %p ), stub\n", cIn, pdblOut );
2925 *pdblOut = (double) cIn;
2930 /******************************************************************************
2931 * VarR8FromUI2 [OLEAUT32.218]
2933 HRESULT WINAPI VarR8FromUI2(USHORT uiIn, double* pdblOut)
2935 TRACE("( %d, %p ), stub\n", uiIn, pdblOut );
2937 *pdblOut = (double) uiIn;
2942 /******************************************************************************
2943 * VarR8FromUI4 [OLEAUT32.219]
2945 HRESULT WINAPI VarR8FromUI4(ULONG ulIn, double* pdblOut)
2947 TRACE("( %ld, %p ), stub\n", ulIn, pdblOut );
2949 *pdblOut = (double) ulIn;
2954 /******************************************************************************
2955 * VarR8FromStr [OLEAUT32.84]
2957 HRESULT WINAPI VarR8FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, double* pdblOut)
2959 double dValue = 0.0;
2960 LPSTR pNewString = NULL;
2962 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pdblOut );
2964 /* Check if we have a valid argument
2966 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
2967 RemoveCharacterFromString( pNewString, "," );
2968 if( IsValidRealString( pNewString ) == FALSE )
2970 return DISP_E_TYPEMISMATCH;
2973 /* Convert the valid string to a floating point number.
2975 dValue = atof( pNewString );
2977 /* We don't need the string anymore so free it.
2979 HeapFree( GetProcessHeap(), 0, pNewString );
2986 /**********************************************************************
2987 * VarR8FromCy [OLEAUT32.82]
2988 * Convert currency to double
2990 HRESULT WINAPI VarR8FromCy(CY cyIn, double* pdblOut) {
2991 *pdblOut = (double)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
2996 /******************************************************************************
2997 * VarDateFromUI1 [OLEAUT32.88]
2999 HRESULT WINAPI VarDateFromUI1(BYTE bIn, DATE* pdateOut)
3001 TRACE("( %d, %p ), stub\n", bIn, pdateOut );
3003 *pdateOut = (DATE) bIn;
3008 /******************************************************************************
3009 * VarDateFromI2 [OLEAUT32.89]
3011 HRESULT WINAPI VarDateFromI2(short sIn, DATE* pdateOut)
3013 TRACE("( %d, %p ), stub\n", sIn, pdateOut );
3015 *pdateOut = (DATE) sIn;
3020 /******************************************************************************
3021 * VarDateFromI4 [OLEAUT32.90]
3023 HRESULT WINAPI VarDateFromI4(LONG lIn, DATE* pdateOut)
3025 TRACE("( %ld, %p ), stub\n", lIn, pdateOut );
3027 if( lIn < DATE_MIN || lIn > DATE_MAX )
3029 return DISP_E_OVERFLOW;
3032 *pdateOut = (DATE) lIn;
3037 /******************************************************************************
3038 * VarDateFromR4 [OLEAUT32.91]
3040 HRESULT WINAPI VarDateFromR4(FLOAT fltIn, DATE* pdateOut)
3042 TRACE("( %f, %p ), stub\n", fltIn, pdateOut );
3044 if( ceil(fltIn) < DATE_MIN || floor(fltIn) > DATE_MAX )
3046 return DISP_E_OVERFLOW;
3049 *pdateOut = (DATE) fltIn;
3054 /******************************************************************************
3055 * VarDateFromR8 [OLEAUT32.92]
3057 HRESULT WINAPI VarDateFromR8(double dblIn, DATE* pdateOut)
3059 TRACE("( %f, %p ), stub\n", dblIn, pdateOut );
3061 if( ceil(dblIn) < DATE_MIN || floor(dblIn) > DATE_MAX )
3063 return DISP_E_OVERFLOW;
3066 *pdateOut = (DATE) dblIn;
3071 /******************************************************************************
3072 * VarDateFromStr [OLEAUT32.94]
3073 * The string representing the date is composed of two parts, a date and time.
3075 * The format of the time is has follows:
3076 * hh[:mm][:ss][AM|PM]
3077 * Whitespace can be inserted anywhere between these tokens. A whitespace consists
3078 * of space and/or tab characters, which are ignored.
3080 * The formats for the date part are has follows:
3084 * January dd[,] [yy]yy
3087 * Whitespace can be inserted anywhere between these tokens.
3089 * The formats for the date and time string are has follows.
3090 * date[whitespace][time]
3091 * [time][whitespace]date
3093 * These are the only characters allowed in a string representing a date and time:
3094 * [A-Z] [a-z] [0-9] ':' '-' '/' ',' ' ' '\t'
3096 HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pdateOut)
3101 memset( &TM, 0, sizeof(TM) );
3103 TRACE("( %p, %lx, %lx, %p ), stub\n", strIn, lcid, dwFlags, pdateOut );
3105 if( DateTimeStringToTm( strIn, dwFlags, &TM ) )
3107 if( TmToDATE( &TM, pdateOut ) == FALSE )
3114 ret = DISP_E_TYPEMISMATCH;
3121 /******************************************************************************
3122 * VarDateFromI1 [OLEAUT32.221]
3124 HRESULT WINAPI VarDateFromI1(CHAR cIn, DATE* pdateOut)
3126 TRACE("( %c, %p ), stub\n", cIn, pdateOut );
3128 *pdateOut = (DATE) cIn;
3133 /******************************************************************************
3134 * VarDateFromUI2 [OLEAUT32.222]
3136 HRESULT WINAPI VarDateFromUI2(USHORT uiIn, DATE* pdateOut)
3138 TRACE("( %d, %p ), stub\n", uiIn, pdateOut );
3140 if( uiIn > DATE_MAX )
3142 return DISP_E_OVERFLOW;
3145 *pdateOut = (DATE) uiIn;
3150 /******************************************************************************
3151 * VarDateFromUI4 [OLEAUT32.223]
3153 HRESULT WINAPI VarDateFromUI4(ULONG ulIn, DATE* pdateOut)
3155 TRACE("( %ld, %p ), stub\n", ulIn, pdateOut );
3157 if( ulIn < DATE_MIN || ulIn > DATE_MAX )
3159 return DISP_E_OVERFLOW;
3162 *pdateOut = (DATE) ulIn;
3167 /******************************************************************************
3168 * VarDateFromBool [OLEAUT32.96]
3170 HRESULT WINAPI VarDateFromBool(VARIANT_BOOL boolIn, DATE* pdateOut)
3172 TRACE("( %d, %p ), stub\n", boolIn, pdateOut );
3174 *pdateOut = (DATE) boolIn;
3179 /**********************************************************************
3180 * VarDateFromCy [OLEAUT32.93]
3181 * Convert currency to date
3183 HRESULT WINAPI VarDateFromCy(CY cyIn, DATE* pdateOut) {
3184 *pdateOut = (DATE)((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3186 if (*pdateOut > DATE_MAX || *pdateOut < DATE_MIN) return DISP_E_TYPEMISMATCH;
3190 /******************************************************************************
3191 * VarBstrFromUI1 [OLEAUT32.108]
3193 HRESULT WINAPI VarBstrFromUI1(BYTE bVal, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3195 TRACE("( %d, %ld, %ld, %p ), stub\n", bVal, lcid, dwFlags, pbstrOut );
3196 sprintf( pBuffer, "%d", bVal );
3198 *pbstrOut = StringDupAtoBstr( pBuffer );
3203 /******************************************************************************
3204 * VarBstrFromI2 [OLEAUT32.109]
3206 HRESULT WINAPI VarBstrFromI2(short iVal, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3208 TRACE("( %d, %ld, %ld, %p ), stub\n", iVal, lcid, dwFlags, pbstrOut );
3209 sprintf( pBuffer, "%d", iVal );
3210 *pbstrOut = StringDupAtoBstr( pBuffer );
3215 /******************************************************************************
3216 * VarBstrFromI4 [OLEAUT32.110]
3218 HRESULT WINAPI VarBstrFromI4(LONG lIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3220 TRACE("( %ld, %ld, %ld, %p ), stub\n", lIn, lcid, dwFlags, pbstrOut );
3222 sprintf( pBuffer, "%ld", lIn );
3223 *pbstrOut = StringDupAtoBstr( pBuffer );
3228 /******************************************************************************
3229 * VarBstrFromR4 [OLEAUT32.111]
3231 HRESULT WINAPI VarBstrFromR4(FLOAT fltIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3233 TRACE("( %f, %ld, %ld, %p ), stub\n", fltIn, lcid, dwFlags, pbstrOut );
3235 sprintf( pBuffer, "%.7g", fltIn );
3236 *pbstrOut = StringDupAtoBstr( pBuffer );
3241 /******************************************************************************
3242 * VarBstrFromR8 [OLEAUT32.112]
3244 HRESULT WINAPI VarBstrFromR8(double dblIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3246 TRACE("( %f, %ld, %ld, %p ), stub\n", dblIn, lcid, dwFlags, pbstrOut );
3248 sprintf( pBuffer, "%.15g", dblIn );
3249 *pbstrOut = StringDupAtoBstr( pBuffer );
3254 /******************************************************************************
3255 * VarBstrFromCy [OLEAUT32.113]
3257 HRESULT WINAPI VarBstrFromCy(CY cyIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut) {
3258 FIXME("([cyIn], %08lx, %08lx, %p), stub.\n", lcid, dwFlags, pbstrOut);
3263 /******************************************************************************
3264 * VarBstrFromDate [OLEAUT32.114]
3266 * The date is implemented using an 8 byte floating-point number.
3267 * Days are represented by whole numbers increments starting with 0.00 as
3268 * being December 30 1899, midnight.
3269 * The hours are expressed as the fractional part of the number.
3270 * December 30 1899 at midnight = 0.00
3271 * January 1 1900 at midnight = 2.00
3272 * January 4 1900 at 6 AM = 5.25
3273 * January 4 1900 at noon = 5.50
3274 * December 29 1899 at midnight = -1.00
3275 * December 18 1899 at midnight = -12.00
3276 * December 18 1899 at 6AM = -12.25
3277 * December 18 1899 at 6PM = -12.75
3278 * December 19 1899 at midnight = -11.00
3279 * The tm structure is as follows:
3281 * int tm_sec; seconds after the minute - [0,59]
3282 * int tm_min; minutes after the hour - [0,59]
3283 * int tm_hour; hours since midnight - [0,23]
3284 * int tm_mday; day of the month - [1,31]
3285 * int tm_mon; months since January - [0,11]
3286 * int tm_year; years
3287 * int tm_wday; days since Sunday - [0,6]
3288 * int tm_yday; days since January 1 - [0,365]
3289 * int tm_isdst; daylight savings time flag
3292 HRESULT WINAPI VarBstrFromDate(DATE dateIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3295 memset( &TM, 0, sizeof(TM) );
3297 TRACE("( %f, %ld, %ld, %p ), stub\n", dateIn, lcid, dwFlags, pbstrOut );
3299 if( DateToTm( dateIn, dwFlags, &TM ) == FALSE )
3301 return E_INVALIDARG;
3304 if( dwFlags & VAR_DATEVALUEONLY )
3305 strftime( pBuffer, BUFFER_MAX, "%x", &TM );
3306 else if( dwFlags & VAR_TIMEVALUEONLY )
3307 strftime( pBuffer, BUFFER_MAX, "%X", &TM );
3309 strftime( pBuffer, BUFFER_MAX, "%x %X", &TM );
3311 *pbstrOut = StringDupAtoBstr( pBuffer );
3316 /******************************************************************************
3317 * VarBstrFromBool [OLEAUT32.116]
3319 HRESULT WINAPI VarBstrFromBool(VARIANT_BOOL boolIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3321 TRACE("( %d, %ld, %ld, %p ), stub\n", boolIn, lcid, dwFlags, pbstrOut );
3323 sprintf( pBuffer, (boolIn == VARIANT_FALSE) ? "False" : "True" );
3325 *pbstrOut = StringDupAtoBstr( pBuffer );
3330 /******************************************************************************
3331 * VarBstrFromI1 [OLEAUT32.229]
3333 HRESULT WINAPI VarBstrFromI1(CHAR cIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3335 TRACE("( %c, %ld, %ld, %p ), stub\n", cIn, lcid, dwFlags, pbstrOut );
3336 sprintf( pBuffer, "%d", cIn );
3337 *pbstrOut = StringDupAtoBstr( pBuffer );
3342 /******************************************************************************
3343 * VarBstrFromUI2 [OLEAUT32.230]
3345 HRESULT WINAPI VarBstrFromUI2(USHORT uiIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3347 TRACE("( %d, %ld, %ld, %p ), stub\n", uiIn, lcid, dwFlags, pbstrOut );
3348 sprintf( pBuffer, "%d", uiIn );
3349 *pbstrOut = StringDupAtoBstr( pBuffer );
3354 /******************************************************************************
3355 * VarBstrFromUI4 [OLEAUT32.231]
3357 HRESULT WINAPI VarBstrFromUI4(ULONG ulIn, LCID lcid, ULONG dwFlags, BSTR* pbstrOut)
3359 TRACE("( %ld, %ld, %ld, %p ), stub\n", ulIn, lcid, dwFlags, pbstrOut );
3360 sprintf( pBuffer, "%ld", ulIn );
3361 *pbstrOut = StringDupAtoBstr( pBuffer );
3366 /******************************************************************************
3367 * VarBoolFromUI1 [OLEAUT32.118]
3369 HRESULT WINAPI VarBoolFromUI1(BYTE bIn, VARIANT_BOOL* pboolOut)
3371 TRACE("( %d, %p ), stub\n", bIn, pboolOut );
3375 *pboolOut = VARIANT_FALSE;
3379 *pboolOut = VARIANT_TRUE;
3385 /******************************************************************************
3386 * VarBoolFromI2 [OLEAUT32.119]
3388 HRESULT WINAPI VarBoolFromI2(short sIn, VARIANT_BOOL* pboolOut)
3390 TRACE("( %d, %p ), stub\n", sIn, pboolOut );
3392 *pboolOut = (sIn) ? VARIANT_TRUE : VARIANT_FALSE;
3397 /******************************************************************************
3398 * VarBoolFromI4 [OLEAUT32.120]
3400 HRESULT WINAPI VarBoolFromI4(LONG lIn, VARIANT_BOOL* pboolOut)
3402 TRACE("( %ld, %p ), stub\n", lIn, pboolOut );
3404 *pboolOut = (lIn) ? VARIANT_TRUE : VARIANT_FALSE;
3409 /******************************************************************************
3410 * VarBoolFromR4 [OLEAUT32.121]
3412 HRESULT WINAPI VarBoolFromR4(FLOAT fltIn, VARIANT_BOOL* pboolOut)
3414 TRACE("( %f, %p ), stub\n", fltIn, pboolOut );
3416 *pboolOut = (fltIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3421 /******************************************************************************
3422 * VarBoolFromR8 [OLEAUT32.122]
3424 HRESULT WINAPI VarBoolFromR8(double dblIn, VARIANT_BOOL* pboolOut)
3426 TRACE("( %f, %p ), stub\n", dblIn, pboolOut );
3428 *pboolOut = (dblIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3433 /******************************************************************************
3434 * VarBoolFromDate [OLEAUT32.123]
3436 HRESULT WINAPI VarBoolFromDate(DATE dateIn, VARIANT_BOOL* pboolOut)
3438 TRACE("( %f, %p ), stub\n", dateIn, pboolOut );
3440 *pboolOut = (dateIn == 0.0) ? VARIANT_FALSE : VARIANT_TRUE;
3445 /******************************************************************************
3446 * VarBoolFromStr [OLEAUT32.125]
3448 HRESULT WINAPI VarBoolFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, VARIANT_BOOL* pboolOut)
3451 char* pNewString = NULL;
3453 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pboolOut );
3455 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3457 if( pNewString == NULL || strlen( pNewString ) == 0 )
3459 ret = DISP_E_TYPEMISMATCH;
3464 if( strncasecmp( pNewString, "True", strlen( pNewString ) ) == 0 )
3466 *pboolOut = VARIANT_TRUE;
3468 else if( strncasecmp( pNewString, "False", strlen( pNewString ) ) == 0 )
3470 *pboolOut = VARIANT_FALSE;
3474 /* Try converting the string to a floating point number.
3476 double dValue = 0.0;
3477 HRESULT res = VarR8FromStr( strIn, lcid, dwFlags, &dValue );
3480 ret = DISP_E_TYPEMISMATCH;
3483 *pboolOut = (dValue == 0.0) ?
3484 VARIANT_FALSE : VARIANT_TRUE;
3488 HeapFree( GetProcessHeap(), 0, pNewString );
3493 /******************************************************************************
3494 * VarBoolFromI1 [OLEAUT32.233]
3496 HRESULT WINAPI VarBoolFromI1(CHAR cIn, VARIANT_BOOL* pboolOut)
3498 TRACE("( %c, %p ), stub\n", cIn, pboolOut );
3500 *pboolOut = (cIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3505 /******************************************************************************
3506 * VarBoolFromUI2 [OLEAUT32.234]
3508 HRESULT WINAPI VarBoolFromUI2(USHORT uiIn, VARIANT_BOOL* pboolOut)
3510 TRACE("( %d, %p ), stub\n", uiIn, pboolOut );
3512 *pboolOut = (uiIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3517 /******************************************************************************
3518 * VarBoolFromUI4 [OLEAUT32.235]
3520 HRESULT WINAPI VarBoolFromUI4(ULONG ulIn, VARIANT_BOOL* pboolOut)
3522 TRACE("( %ld, %p ), stub\n", ulIn, pboolOut );
3524 *pboolOut = (ulIn == 0) ? VARIANT_FALSE : VARIANT_TRUE;
3529 /**********************************************************************
3530 * VarBoolFromCy [OLEAUT32.124]
3531 * Convert currency to boolean
3533 HRESULT WINAPI VarBoolFromCy(CY cyIn, VARIANT_BOOL* pboolOut) {
3534 if (cyIn.s.Hi || cyIn.s.Lo) *pboolOut = -1;
3540 /******************************************************************************
3541 * VarI1FromUI1 [OLEAUT32.244]
3543 HRESULT WINAPI VarI1FromUI1(BYTE bIn, CHAR* pcOut)
3545 TRACE("( %d, %p ), stub\n", bIn, pcOut );
3547 /* Check range of value.
3549 if( bIn > CHAR_MAX )
3551 return DISP_E_OVERFLOW;
3554 *pcOut = (CHAR) bIn;
3559 /******************************************************************************
3560 * VarI1FromI2 [OLEAUT32.245]
3562 HRESULT WINAPI VarI1FromI2(short uiIn, CHAR* pcOut)
3564 TRACE("( %d, %p ), stub\n", uiIn, pcOut );
3566 if( uiIn > CHAR_MAX )
3568 return DISP_E_OVERFLOW;
3571 *pcOut = (CHAR) uiIn;
3576 /******************************************************************************
3577 * VarI1FromI4 [OLEAUT32.246]
3579 HRESULT WINAPI VarI1FromI4(LONG lIn, CHAR* pcOut)
3581 TRACE("( %ld, %p ), stub\n", lIn, pcOut );
3583 if( lIn < CHAR_MIN || lIn > CHAR_MAX )
3585 return DISP_E_OVERFLOW;
3588 *pcOut = (CHAR) lIn;
3593 /******************************************************************************
3594 * VarI1FromR4 [OLEAUT32.247]
3596 HRESULT WINAPI VarI1FromR4(FLOAT fltIn, CHAR* pcOut)
3598 TRACE("( %f, %p ), stub\n", fltIn, pcOut );
3600 fltIn = round( fltIn );
3601 if( fltIn < CHAR_MIN || fltIn > CHAR_MAX )
3603 return DISP_E_OVERFLOW;
3606 *pcOut = (CHAR) fltIn;
3611 /******************************************************************************
3612 * VarI1FromR8 [OLEAUT32.248]
3614 HRESULT WINAPI VarI1FromR8(double dblIn, CHAR* pcOut)
3616 TRACE("( %f, %p ), stub\n", dblIn, pcOut );
3618 dblIn = round( dblIn );
3619 if( dblIn < CHAR_MIN || dblIn > CHAR_MAX )
3621 return DISP_E_OVERFLOW;
3624 *pcOut = (CHAR) dblIn;
3629 /******************************************************************************
3630 * VarI1FromDate [OLEAUT32.249]
3632 HRESULT WINAPI VarI1FromDate(DATE dateIn, CHAR* pcOut)
3634 TRACE("( %f, %p ), stub\n", dateIn, pcOut );
3636 dateIn = round( dateIn );
3637 if( dateIn < CHAR_MIN || dateIn > CHAR_MAX )
3639 return DISP_E_OVERFLOW;
3642 *pcOut = (CHAR) dateIn;
3647 /******************************************************************************
3648 * VarI1FromStr [OLEAUT32.251]
3650 HRESULT WINAPI VarI1FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, CHAR* pcOut)
3652 double dValue = 0.0;
3653 LPSTR pNewString = NULL;
3655 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pcOut );
3657 /* Check if we have a valid argument
3659 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3660 RemoveCharacterFromString( pNewString, "," );
3661 if( IsValidRealString( pNewString ) == FALSE )
3663 return DISP_E_TYPEMISMATCH;
3666 /* Convert the valid string to a floating point number.
3668 dValue = atof( pNewString );
3670 /* We don't need the string anymore so free it.
3672 HeapFree( GetProcessHeap(), 0, pNewString );
3674 /* Check range of value.
3676 dValue = round( dValue );
3677 if( dValue < CHAR_MIN || dValue > CHAR_MAX )
3679 return DISP_E_OVERFLOW;
3682 *pcOut = (CHAR) dValue;
3687 /******************************************************************************
3688 * VarI1FromBool [OLEAUT32.253]
3690 HRESULT WINAPI VarI1FromBool(VARIANT_BOOL boolIn, CHAR* pcOut)
3692 TRACE("( %d, %p ), stub\n", boolIn, pcOut );
3694 *pcOut = (CHAR) boolIn;
3699 /******************************************************************************
3700 * VarI1FromUI2 [OLEAUT32.254]
3702 HRESULT WINAPI VarI1FromUI2(USHORT uiIn, CHAR* pcOut)
3704 TRACE("( %d, %p ), stub\n", uiIn, pcOut );
3706 if( uiIn > CHAR_MAX )
3708 return DISP_E_OVERFLOW;
3711 *pcOut = (CHAR) uiIn;
3716 /******************************************************************************
3717 * VarI1FromUI4 [OLEAUT32.255]
3719 HRESULT WINAPI VarI1FromUI4(ULONG ulIn, CHAR* pcOut)
3721 TRACE("( %ld, %p ), stub\n", ulIn, pcOut );
3723 if( ulIn > CHAR_MAX )
3725 return DISP_E_OVERFLOW;
3728 *pcOut = (CHAR) ulIn;
3733 /**********************************************************************
3734 * VarI1FromCy [OLEAUT32.250]
3735 * Convert currency to signed char
3737 HRESULT WINAPI VarI1FromCy(CY cyIn, CHAR* pcOut) {
3738 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3740 if (t > CHAR_MAX || t < CHAR_MIN) return DISP_E_OVERFLOW;
3746 /******************************************************************************
3747 * VarUI2FromUI1 [OLEAUT32.257]
3749 HRESULT WINAPI VarUI2FromUI1(BYTE bIn, USHORT* puiOut)
3751 TRACE("( %d, %p ), stub\n", bIn, puiOut );
3753 *puiOut = (USHORT) bIn;
3758 /******************************************************************************
3759 * VarUI2FromI2 [OLEAUT32.258]
3761 HRESULT WINAPI VarUI2FromI2(short uiIn, USHORT* puiOut)
3763 TRACE("( %d, %p ), stub\n", uiIn, puiOut );
3765 if( uiIn < UI2_MIN )
3767 return DISP_E_OVERFLOW;
3770 *puiOut = (USHORT) uiIn;
3775 /******************************************************************************
3776 * VarUI2FromI4 [OLEAUT32.259]
3778 HRESULT WINAPI VarUI2FromI4(LONG lIn, USHORT* puiOut)
3780 TRACE("( %ld, %p ), stub\n", lIn, puiOut );
3782 if( lIn < UI2_MIN || lIn > UI2_MAX )
3784 return DISP_E_OVERFLOW;
3787 *puiOut = (USHORT) lIn;
3792 /******************************************************************************
3793 * VarUI2FromR4 [OLEAUT32.260]
3795 HRESULT WINAPI VarUI2FromR4(FLOAT fltIn, USHORT* puiOut)
3797 TRACE("( %f, %p ), stub\n", fltIn, puiOut );
3799 fltIn = round( fltIn );
3800 if( fltIn < UI2_MIN || fltIn > UI2_MAX )
3802 return DISP_E_OVERFLOW;
3805 *puiOut = (USHORT) fltIn;
3810 /******************************************************************************
3811 * VarUI2FromR8 [OLEAUT32.261]
3813 HRESULT WINAPI VarUI2FromR8(double dblIn, USHORT* puiOut)
3815 TRACE("( %f, %p ), stub\n", dblIn, puiOut );
3817 dblIn = round( dblIn );
3818 if( dblIn < UI2_MIN || dblIn > UI2_MAX )
3820 return DISP_E_OVERFLOW;
3823 *puiOut = (USHORT) dblIn;
3828 /******************************************************************************
3829 * VarUI2FromDate [OLEAUT32.262]
3831 HRESULT WINAPI VarUI2FromDate(DATE dateIn, USHORT* puiOut)
3833 TRACE("( %f, %p ), stub\n", dateIn, puiOut );
3835 dateIn = round( dateIn );
3836 if( dateIn < UI2_MIN || dateIn > UI2_MAX )
3838 return DISP_E_OVERFLOW;
3841 *puiOut = (USHORT) dateIn;
3846 /******************************************************************************
3847 * VarUI2FromStr [OLEAUT32.264]
3849 HRESULT WINAPI VarUI2FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, USHORT* puiOut)
3851 double dValue = 0.0;
3852 LPSTR pNewString = NULL;
3854 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, puiOut );
3856 /* Check if we have a valid argument
3858 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3859 RemoveCharacterFromString( pNewString, "," );
3860 if( IsValidRealString( pNewString ) == FALSE )
3862 return DISP_E_TYPEMISMATCH;
3865 /* Convert the valid string to a floating point number.
3867 dValue = atof( pNewString );
3869 /* We don't need the string anymore so free it.
3871 HeapFree( GetProcessHeap(), 0, pNewString );
3873 /* Check range of value.
3875 dValue = round( dValue );
3876 if( dValue < UI2_MIN || dValue > UI2_MAX )
3878 return DISP_E_OVERFLOW;
3881 *puiOut = (USHORT) dValue;
3886 /******************************************************************************
3887 * VarUI2FromBool [OLEAUT32.266]
3889 HRESULT WINAPI VarUI2FromBool(VARIANT_BOOL boolIn, USHORT* puiOut)
3891 TRACE("( %d, %p ), stub\n", boolIn, puiOut );
3893 *puiOut = (USHORT) boolIn;
3898 /******************************************************************************
3899 * VarUI2FromI1 [OLEAUT32.267]
3901 HRESULT WINAPI VarUI2FromI1(CHAR cIn, USHORT* puiOut)
3903 TRACE("( %c, %p ), stub\n", cIn, puiOut );
3905 *puiOut = (USHORT) cIn;
3910 /******************************************************************************
3911 * VarUI2FromUI4 [OLEAUT32.268]
3913 HRESULT WINAPI VarUI2FromUI4(ULONG ulIn, USHORT* puiOut)
3915 TRACE("( %ld, %p ), stub\n", ulIn, puiOut );
3917 if( ulIn < UI2_MIN || ulIn > UI2_MAX )
3919 return DISP_E_OVERFLOW;
3922 *puiOut = (USHORT) ulIn;
3927 /******************************************************************************
3928 * VarUI4FromStr [OLEAUT32.277]
3930 HRESULT WINAPI VarUI4FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, ULONG* pulOut)
3932 double dValue = 0.0;
3933 LPSTR pNewString = NULL;
3935 TRACE("( %p, %ld, %ld, %p ), stub\n", strIn, lcid, dwFlags, pulOut );
3937 /* Check if we have a valid argument
3939 pNewString = HEAP_strdupWtoA( GetProcessHeap(), 0, strIn );
3940 RemoveCharacterFromString( pNewString, "," );
3941 if( IsValidRealString( pNewString ) == FALSE )
3943 return DISP_E_TYPEMISMATCH;
3946 /* Convert the valid string to a floating point number.
3948 dValue = atof( pNewString );
3950 /* We don't need the string anymore so free it.
3952 HeapFree( GetProcessHeap(), 0, pNewString );
3954 /* Check range of value.
3956 dValue = round( dValue );
3957 if( dValue < UI4_MIN || dValue > UI4_MAX )
3959 return DISP_E_OVERFLOW;
3962 *pulOut = (ULONG) dValue;
3967 /**********************************************************************
3968 * VarUI2FromCy [OLEAUT32.263]
3969 * Convert currency to unsigned short
3971 HRESULT WINAPI VarUI2FromCy(CY cyIn, USHORT* pusOut) {
3972 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
3974 if (t > UI2_MAX || t < UI2_MIN) return DISP_E_OVERFLOW;
3976 *pusOut = (USHORT)t;
3981 /******************************************************************************
3982 * VarUI4FromUI1 [OLEAUT32.270]
3984 HRESULT WINAPI VarUI4FromUI1(BYTE bIn, ULONG* pulOut)
3986 TRACE("( %d, %p ), stub\n", bIn, pulOut );
3988 *pulOut = (USHORT) bIn;
3993 /******************************************************************************
3994 * VarUI4FromI2 [OLEAUT32.271]
3996 HRESULT WINAPI VarUI4FromI2(short uiIn, ULONG* pulOut)
3998 TRACE("( %d, %p ), stub\n", uiIn, pulOut );
4000 if( uiIn < UI4_MIN )
4002 return DISP_E_OVERFLOW;
4005 *pulOut = (ULONG) uiIn;
4010 /******************************************************************************
4011 * VarUI4FromI4 [OLEAUT32.272]
4013 HRESULT WINAPI VarUI4FromI4(LONG lIn, ULONG* pulOut)
4015 TRACE("( %ld, %p ), stub\n", lIn, pulOut );
4019 return DISP_E_OVERFLOW;
4022 *pulOut = (ULONG) lIn;
4027 /******************************************************************************
4028 * VarUI4FromR4 [OLEAUT32.273]
4030 HRESULT WINAPI VarUI4FromR4(FLOAT fltIn, ULONG* pulOut)
4032 fltIn = round( fltIn );
4033 if( fltIn < UI4_MIN || fltIn > UI4_MAX )
4035 return DISP_E_OVERFLOW;
4038 *pulOut = (ULONG) fltIn;
4043 /******************************************************************************
4044 * VarUI4FromR8 [OLEAUT32.274]
4046 HRESULT WINAPI VarUI4FromR8(double dblIn, ULONG* pulOut)
4048 TRACE("( %f, %p ), stub\n", dblIn, pulOut );
4050 dblIn = round( dblIn );
4051 if( dblIn < UI4_MIN || dblIn > UI4_MAX )
4053 return DISP_E_OVERFLOW;
4056 *pulOut = (ULONG) dblIn;
4061 /******************************************************************************
4062 * VarUI4FromDate [OLEAUT32.275]
4064 HRESULT WINAPI VarUI4FromDate(DATE dateIn, ULONG* pulOut)
4066 TRACE("( %f, %p ), stub\n", dateIn, pulOut );
4068 dateIn = round( dateIn );
4069 if( dateIn < UI4_MIN || dateIn > UI4_MAX )
4071 return DISP_E_OVERFLOW;
4074 *pulOut = (ULONG) dateIn;
4079 /******************************************************************************
4080 * VarUI4FromBool [OLEAUT32.279]
4082 HRESULT WINAPI VarUI4FromBool(VARIANT_BOOL boolIn, ULONG* pulOut)
4084 TRACE("( %d, %p ), stub\n", boolIn, pulOut );
4086 *pulOut = (ULONG) boolIn;
4091 /******************************************************************************
4092 * VarUI4FromI1 [OLEAUT32.280]
4094 HRESULT WINAPI VarUI4FromI1(CHAR cIn, ULONG* pulOut)
4096 TRACE("( %c, %p ), stub\n", cIn, pulOut );
4098 *pulOut = (ULONG) cIn;
4103 /******************************************************************************
4104 * VarUI4FromUI2 [OLEAUT32.281]
4106 HRESULT WINAPI VarUI4FromUI2(USHORT uiIn, ULONG* pulOut)
4108 TRACE("( %d, %p ), stub\n", uiIn, pulOut );
4110 *pulOut = (ULONG) uiIn;
4115 /**********************************************************************
4116 * VarUI4FromCy [OLEAUT32.276]
4117 * Convert currency to unsigned long
4119 HRESULT WINAPI VarUI4FromCy(CY cyIn, ULONG* pulOut) {
4120 double t = round((((double)cyIn.s.Hi * 4294967296.0) + (double)cyIn.s.Lo) / 10000);
4122 if (t > UI4_MAX || t < UI4_MIN) return DISP_E_OVERFLOW;
4129 /**********************************************************************
4130 * VarCyFromUI1 [OLEAUT32.98]
4131 * Convert unsigned char to currency
4133 HRESULT WINAPI VarCyFromUI1(BYTE bIn, CY* pcyOut) {
4135 pcyOut->s.Lo = ((ULONG)bIn) * 10000;
4140 /**********************************************************************
4141 * VarCyFromI2 [OLEAUT32.99]
4142 * Convert signed short to currency
4144 HRESULT WINAPI VarCyFromI2(short sIn, CY* pcyOut) {
4145 if (sIn < 0) pcyOut->s.Hi = -1;
4146 else pcyOut->s.Hi = 0;
4147 pcyOut->s.Lo = ((ULONG)sIn) * 10000;
4152 /**********************************************************************
4153 * VarCyFromI4 [OLEAUT32.100]
4154 * Convert signed long to currency
4156 HRESULT WINAPI VarCyFromI4(LONG lIn, CY* pcyOut) {
4157 double t = (double)lIn * (double)10000;
4158 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4159 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4160 if (lIn < 0) pcyOut->s.Hi--;
4165 /**********************************************************************
4166 * VarCyFromR4 [OLEAUT32.101]
4167 * Convert float to currency
4169 HRESULT WINAPI VarCyFromR4(FLOAT fltIn, CY* pcyOut) {
4170 double t = round((double)fltIn * (double)10000);
4171 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4172 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4173 if (fltIn < 0) pcyOut->s.Hi--;
4178 /**********************************************************************
4179 * VarCyFromR8 [OLEAUT32.102]
4180 * Convert double to currency
4182 HRESULT WINAPI VarCyFromR8(double dblIn, CY* pcyOut) {
4183 double t = round(dblIn * (double)10000);
4184 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4185 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4186 if (dblIn < 0) pcyOut->s.Hi--;
4191 /**********************************************************************
4192 * VarCyFromDate [OLEAUT32.103]
4193 * Convert date to currency
4195 HRESULT WINAPI VarCyFromDate(DATE dateIn, CY* pcyOut) {
4196 double t = round((double)dateIn * (double)10000);
4197 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4198 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4199 if (dateIn < 0) pcyOut->s.Hi--;
4204 /**********************************************************************
4205 * VarCyFromStr [OLEAUT32.104]
4207 HRESULT WINAPI VarCyFromStr(OLECHAR *strIn, LCID lcid, ULONG dwFlags, CY *pcyOut) {
4208 FIXME("(%p, %08lx, %08lx, %p), stub.\n", strIn, lcid, dwFlags, pcyOut);
4213 /**********************************************************************
4214 * VarCyFromBool [OLEAUT32.106]
4215 * Convert boolean to currency
4217 HRESULT WINAPI VarCyFromBool(VARIANT_BOOL boolIn, CY* pcyOut) {
4218 if (boolIn < 0) pcyOut->s.Hi = -1;
4219 else pcyOut->s.Hi = 0;
4220 pcyOut->s.Lo = (ULONG)boolIn * (ULONG)10000;
4225 /**********************************************************************
4226 * VarCyFromI1 [OLEAUT32.225]
4227 * Convert signed char to currency
4229 HRESULT WINAPI VarCyFromI1(signed char cIn, CY* pcyOut) {
4230 if (cIn < 0) pcyOut->s.Hi = -1;
4231 else pcyOut->s.Hi = 0;
4232 pcyOut->s.Lo = (ULONG)cIn * (ULONG)10000;
4237 /**********************************************************************
4238 * VarCyFromUI2 [OLEAUT32.226]
4239 * Convert unsigned short to currency
4241 HRESULT WINAPI VarCyFromUI2(USHORT usIn, CY* pcyOut) {
4243 pcyOut->s.Lo = (ULONG)usIn * (ULONG)10000;
4248 /**********************************************************************
4249 * VarCyFromUI4 [OLEAUT32.227]
4250 * Convert unsigned long to currency
4252 HRESULT WINAPI VarCyFromUI4(ULONG ulIn, CY* pcyOut) {
4253 double t = (double)ulIn * (double)10000;
4254 pcyOut->s.Hi = (LONG)(t / (double)4294967296.0);
4255 pcyOut->s.Lo = (ULONG)fmod(t, (double)4294967296.0);
4261 /**********************************************************************
4262 * DosDateTimeToVariantTime [OLEAUT32.14]
4263 * Convert dos representation of time to the date and time representation
4264 * stored in a variant.
4266 INT WINAPI DosDateTimeToVariantTime(USHORT wDosDate, USHORT wDosTime,
4271 TRACE("( 0x%x, 0x%x, %p ), stub\n", wDosDate, wDosTime, pvtime );
4273 t.tm_sec = (wDosTime & 0x001f) * 2;
4274 t.tm_min = (wDosTime & 0x07e0) >> 5;
4275 t.tm_hour = (wDosTime & 0xf800) >> 11;
4277 t.tm_mday = (wDosDate & 0x001f);
4278 t.tm_mon = (wDosDate & 0x01e0) >> 5;
4279 t.tm_year = ((wDosDate & 0xfe00) >> 9) + 1980;
4281 return TmToDATE( &t, pvtime );
4285 /**********************************************************************
4286 * VarParseNumFromStr [OLEAUT32.46]
4288 HRESULT WINAPI VarParseNumFromStr(OLECHAR * strIn, LCID lcid, ULONG dwFlags,
4289 NUMPARSE * pnumprs, BYTE * rgbDig)
4293 FIXME("(%s,flags=%lx,....), partial stub!\n",debugstr_w(strIn),dwFlags);
4294 FIXME("numparse: cDig=%d, InFlags=%lx\n",pnumprs->cDig,pnumprs->dwInFlags);
4296 /* The other struct components are to be set by us */
4298 memset(rgbDig,0,pnumprs->cDig);
4301 for (i=0; strIn[i] ;i++) {
4302 if ((strIn[i]>='0') && (strIn[i]<='9')) {
4303 if (pnumprs->cDig > cDig) {
4304 *(rgbDig++)=strIn[i]-'0';
4310 pnumprs->cDig = cDig;
4312 /* FIXME: Just patching some values in */
4313 pnumprs->nPwr10 = 0;
4314 pnumprs->nBaseShift = 0;
4315 pnumprs->cchUsed = lastent;
4316 pnumprs->dwOutFlags = NUMPRS_DECIMAL;
4321 /**********************************************************************
4322 * VarNumFromParseNum [OLEAUT32.47]
4324 HRESULT WINAPI VarNumFromParseNum(NUMPARSE * pnumprs, BYTE * rgbDig,
4325 ULONG dwVtBits, VARIANT * pvar)
4329 FIXME("(,dwVtBits=%lx,....), partial stub!\n",dwVtBits);
4332 for (i=0;i<pnumprs->cDig;i++)
4333 xint = xint*10 + rgbDig[i];
4336 if (dwVtBits & VTBIT_I4) {
4338 V_UNION(pvar,intVal) = xint;
4341 if (dwVtBits & VTBIT_R8) {
4343 V_UNION(pvar,dblVal) = xint;
4346 FIXME("vtbitmask is unsupported %lx\n",dwVtBits);
4352 /**********************************************************************
4353 * VariantTimeToDosDateTime [OLEAUT32.13]
4354 * Convert variant representation of time to the date and time representation
4357 INT WINAPI VariantTimeToDosDateTime(DATE pvtime, USHORT *wDosDate, USHORT *wDosTime)
4363 TRACE("( 0x%x, 0x%x, %p ), stub\n", *wDosDate, *wDosTime, &pvtime );
4365 if (DateToTm(pvtime, 0, &t) < 0) return 0;
4367 *wDosTime = *wDosTime | (t.tm_sec / 2);
4368 *wDosTime = *wDosTime | (t.tm_min << 5);
4369 *wDosTime = *wDosTime | (t.tm_hour << 11);
4371 *wDosDate = *wDosDate | t.tm_mday ;
4372 *wDosDate = *wDosDate | t.tm_mon << 5;
4373 *wDosDate = *wDosDate | ((t.tm_year - 1980) << 9) ;
4379 /***********************************************************************
4380 * SystemTimeToVariantTime [OLEAUT32.184]
4382 HRESULT WINAPI SystemTimeToVariantTime( LPSYSTEMTIME lpSystemTime, double *pvtime )
4384 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4385 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4389 TRACE(" %d/%d/%d %d:%d:%d\n",
4390 lpSystemTime->wMonth, lpSystemTime->wDay,
4391 lpSystemTime->wYear, lpSystemTime->wHour,
4392 lpSystemTime->wMinute, lpSystemTime->wSecond);
4394 if (lpSystemTime->wYear >= 1900)
4396 t.tm_sec = lpSystemTime->wSecond;
4397 t.tm_min = lpSystemTime->wMinute;
4398 t.tm_hour = lpSystemTime->wHour;
4400 t.tm_mday = lpSystemTime->wDay;
4401 t.tm_mon = lpSystemTime->wMonth;
4402 t.tm_year = lpSystemTime->wYear;
4404 return TmToDATE( &t, pvtime );
4408 t.tm_sec = lpSystemTime->wSecond;
4409 t.tm_min = lpSystemTime->wMinute;
4410 t.tm_hour = lpSystemTime->wHour;
4412 if (isleap(lpSystemTime->wYear) )
4413 t.tm_mday = Days_Per_Month_LY[13 - lpSystemTime->wMonth] - lpSystemTime->wDay;
4415 t.tm_mday = Days_Per_Month[13 - lpSystemTime->wMonth] - lpSystemTime->wDay;
4417 t.tm_mon = 13 - lpSystemTime->wMonth;
4418 t.tm_year = 1900 + 1899 - lpSystemTime->wYear;
4420 TmToDATE( &t, pvtime );
4430 /***********************************************************************
4431 * VariantTimeToSystemTime [OLEAUT32.185]
4433 HRESULT WINAPI VariantTimeToSystemTime( double vtime, LPSYSTEMTIME lpSystemTime )
4435 double t = 0, timeofday = 0;
4437 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4438 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4440 /* The Month_Code is used to find the Day of the Week (LY = LeapYear)*/
4441 static const BYTE Month_Code[] = {0, 1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};
4442 static const BYTE Month_Code_LY[] = {0, 0, 3, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};
4444 /* The Century_Code is used to find the Day of the Week */
4445 static const BYTE Century_Code[] = {0, 6, 4, 2};
4449 TRACE(" Variant = %f SYSTEMTIME ptr %p", vtime, lpSystemTime);
4454 if (DateToTm(vtime, 0, &r ) <= 0) return 0;
4456 lpSystemTime->wSecond = r.tm_sec;
4457 lpSystemTime->wMinute = r.tm_min;
4458 lpSystemTime->wHour = r.tm_hour;
4459 lpSystemTime->wDay = r.tm_mday;
4460 lpSystemTime->wMonth = r.tm_mon;
4462 if (lpSystemTime->wMonth == 12)
4463 lpSystemTime->wMonth = 1;
4465 lpSystemTime->wMonth++;
4467 lpSystemTime->wYear = r.tm_year;
4473 if (DateToTm(vtime, 0, &r ) <= 0) return 0;
4475 lpSystemTime->wSecond = r.tm_sec;
4476 lpSystemTime->wMinute = r.tm_min;
4477 lpSystemTime->wHour = r.tm_hour;
4479 lpSystemTime->wMonth = 13 - r.tm_mon;
4481 if (lpSystemTime->wMonth == 1)
4482 lpSystemTime->wMonth = 12;
4484 lpSystemTime->wMonth--;
4486 lpSystemTime->wYear = 1899 - (r.tm_year - 1900);
4488 if (!isleap(lpSystemTime->wYear) )
4489 lpSystemTime->wDay = Days_Per_Month[13 - lpSystemTime->wMonth] - r.tm_mday;
4491 lpSystemTime->wDay = Days_Per_Month_LY[13 - lpSystemTime->wMonth] - r.tm_mday;
4496 if (!isleap(lpSystemTime->wYear))
4499 (Century_Code+Month_Code+Year_Code+Day) % 7
4501 The century code repeats every 400 years , so the array
4502 works out like this,
4504 Century_Code[0] is for 16th/20th Centry
4505 Century_Code[1] is for 17th/21th Centry
4506 Century_Code[2] is for 18th/22th Centry
4507 Century_Code[3] is for 19th/23th Centry
4509 The year code is found with the formula (year + (year / 4))
4510 the "year" must be between 0 and 99 .
4512 The Month Code (Month_Code[1]) starts with January and
4516 lpSystemTime->wDayOfWeek = (
4517 Century_Code[(( (lpSystemTime->wYear+100) - lpSystemTime->wYear%100) /100) %4]+
4518 ((lpSystemTime->wYear%100)+(lpSystemTime->wYear%100)/4)+
4519 Month_Code[lpSystemTime->wMonth]+
4520 lpSystemTime->wDay) % 7;
4522 if (lpSystemTime->wDayOfWeek == 0) lpSystemTime->wDayOfWeek = 7;
4523 else lpSystemTime->wDayOfWeek -= 1;
4527 lpSystemTime->wDayOfWeek = (
4528 Century_Code[(((lpSystemTime->wYear+100) - lpSystemTime->wYear%100)/100)%4]+
4529 ((lpSystemTime->wYear%100)+(lpSystemTime->wYear%100)/4)+
4530 Month_Code_LY[lpSystemTime->wMonth]+
4531 lpSystemTime->wDay) % 7;
4533 if (lpSystemTime->wDayOfWeek == 0) lpSystemTime->wDayOfWeek = 7;
4534 else lpSystemTime->wDayOfWeek -= 1;
4538 timeofday = vtime - t;
4540 lpSystemTime->wMilliseconds = (timeofday
4541 - lpSystemTime->wHour*(1/24)
4542 - lpSystemTime->wMinute*(1/1440)
4543 - lpSystemTime->wSecond*(1/86400) )*(1/5184000);
4548 /***********************************************************************
4549 * VarUdateFromDate [OLEAUT32.331]
4551 HRESULT WINAPI VarUdateFromDate( DATE datein, ULONG dwFlags, UDATE *pudateout)
4554 static const BYTE Days_Per_Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4555 static const BYTE Days_Per_Month_LY[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4557 TRACE("DATE = %f\n", (double)datein);
4558 i = VariantTimeToSystemTime(datein, &(pudateout->st) );
4562 pudateout->wDayOfYear = 0;
4564 if (isleap(pudateout->st.wYear))
4566 for (i =1; i<pudateout->st.wMonth; i++)
4567 pudateout->wDayOfYear += Days_Per_Month[i];
4571 for (i =1; i<pudateout->st.wMonth; i++)
4572 pudateout->wDayOfYear += Days_Per_Month_LY[i];
4575 pudateout->wDayOfYear += pudateout->st.wDay;
4576 dwFlags = 0; /*VAR_VALIDDATE*/
4583 /***********************************************************************
4584 * VarDateFromUdate [OLEAUT32.330]
4586 HRESULT WINAPI VarDateFromUdate(UDATE *pudateout,
4587 ULONG dwFlags, DATE *datein)
4591 TRACE(" %d/%d/%d %d:%d:%d\n",
4592 pudateout->st.wMonth, pudateout->st.wDay,
4593 pudateout->st.wYear, pudateout->st.wHour,
4594 pudateout->st.wMinute, pudateout->st.wSecond);
4597 i = SystemTimeToVariantTime(&(pudateout->st), &t);
4600 if (i) dwFlags = 0; /*VAR_VALIDDATE*/
4607 /**********************************************************************
4608 * VarBstrCmp [OLEAUT32.440]
4611 * NORM_IGNORECASE, NORM_IGNORENONSPACE, NORM_IGNORESYMBOLS
4612 * NORM_IGNORESTRINGWIDTH, NORM_IGNOREKANATYPE, NORM_IGNOREKASHIDA
4615 HRESULT WINAPI VarBstrCmp(BSTR left, BSTR right, LCID lcid, DWORD flags)
4619 FIXME("( %s %s %ld %lx ) partial stub\n", debugstr_w(left), debugstr_w(right), lcid, flags);
4621 if((!left) || (!right))
4624 if(flags&NORM_IGNORECASE)
4625 r = lstrcmpiW(left,right);
4627 r = lstrcmpW(left,right);
4637 /**********************************************************************
4638 * VarBstrCat [OLEAUT32.439]
4640 HRESULT WINAPI VarBstrCat(BSTR left, BSTR right, BSTR *out)
4644 TRACE("( %s %s %p )\n", debugstr_w(left), debugstr_w(right), out);
4646 if( (!left) || (!right) || (!out) )
4649 result = SysAllocStringLen(left, lstrlenW(left)+lstrlenW(right));
4650 lstrcatW(result,right);
4657 /**********************************************************************
4658 * VarCat [OLEAUT32.441]
4660 HRESULT WINAPI VarCat(LPVARIANT left, LPVARIANT right, LPVARIANT out)
4662 /* Should we VariantClear out? */
4663 /* Can we handle array, vector, by ref etc. */
4664 if ((V_VT(left)&VT_TYPEMASK) == VT_NULL &&
4665 (V_VT(right)&VT_TYPEMASK) == VT_NULL)
4667 V_VT(out) = VT_NULL;
4670 else if (V_VT(left) == VT_BSTR && V_VT(right) == VT_BSTR)
4672 V_VT(out) = VT_BSTR;
4673 VarBstrCat (V_BSTR(left), V_BSTR(right), &V_BSTR(out));
4677 FIXME ("types not supported\n");