Data Type Conversion APIs

The files Oleaut32.dll (for 32-bit systems) and Ole2disp.dll (for 16-bit systems) provide the following low-level functions for converting variant data types. Higher-level variant manipulation functions (such as VariantChangeType) use these functions, but they can also be called directly.

Convert to type From type Function
unsigned char unsigned char None
short VarUI1FromI2(sIn, pbOut)
long VarUI1FromI4(lIn, pbOut)
float VarUI1FromR4(fltIn, pbOut)
double VarUI1FromR8(dblIn, pbOut)
CURRENCY VarUI1FromCy(cyIn, pbOut)
DATE VarUI1FromDate(dateIn, pbOut)
OLECHAR FAR* VarUI1FromStr(strIn, lcid, dwFlags, pbOut)
IDispatch FAR* VarUI1FromDisp(pdispIn, lcid, pbOut)
BOOL VarUI1FromBool(boolIn, pbOut)
short unsigned char VarI2FromUI1(bIn, psOut)
short None
long VarI2FromI4(lIn, psOut)
float VarI2FromR4(fltIn, psOut)
double VarI2FromR8(dblIn, psOut)
CURRENCY VarI2FromCy(cyIn, psOut)
DATE VarI2FromDate(dateIn, psOut)
OLECHAR FAR* VarI2FromStr(strIn, lcid, dwFlags, psOut)
IDispatch FAR* VarI2FromDisp(pdispIn, lcid, psOut)
BOOL VarI2FromBool(boolIn, psOut)
long unsigned char VarI4FromUI1(bIn, plOut)
short VarI4FromI2(sIn, plOut)
long None
float VarI4FromR4(fltIn, plOut)
double VarI4FromR8(dblIn, plOut)
CURRENCY VarI4FromCy(cyIn, plOut)
DATE VarI4FromDate(dateIn, plOut)
OLECHAR FAR* VarI4FromStr(strIn, lcid, dwFlags, plOut)
IDispatch FAR* VarI4FromDisp(pdispIn, lcid, plOut)
BOOL VarI4FromBool(boolIn, plOut)
float unsigned char VarR4FromUI1(bIn, pfltOut)
short VarR4FromI2(sIn, pfltOut)
long VarR4FromI4(lIn, pfltOut)
float None
double VarR4FromR8(dblIn, pfltOut)
CURRENCY VarR4FromCy(cyIn, pfltOut)
DATE VarR4FromDate(dateIn, pfltOut)
OLECHAR FAR* VarR4FromStr(strIn, lcid, dwFlags, pfltOut)
IDispatch FAR* VarR4FromDisp(pdispIn, lcid, pfltOut)
BOOL VarR4FromBool(boolIn, pfltOut)
double unsigned char VarR8FromUI1(bIn, pdblOut)
short VarR8FromI2(sIn, pdblOut)
long VarR8FromI4(lIn, pdblOut)
float VarR8FromR4(fltIn, pdblOut)
double None
CURRENCY VarR8FromCy(cyIn, pdblOut)
DATE VarR8FromDate(dateIn, pdblOut)
OLECHAR FAR* VarR8FromStr(strIn, lcid, dwFlags, pdblOut)
IDispatch FAR* VarR8FromDisp(pdispIn, lcid, pdblOut)
BOOL VarR8FromBool(boolIn, pdblOut)
DATE unsigned char VarDateFromUI1(bIn, pdateOut)
short VarDateFromI2(sIn, pdateOut)
long VarDateFromI4(lIn, pdateOut)
float VarDateFromR4(fltIn, pdateOut)
double VarDateFromR8(dblIn, pdateOut)
CURRENCY VarDateFromCy(cyIn, pdateOut)
DATE None
OLECHAR FAR* VarDateFromStr(strIn, lcid, dwFlags, pdateOut)
IDispatch FAR* VarDateFromDisp(pdispIn, lcid, pdateOut)
BOOL VarDateFromBool(boolIn, pdateOut)
CURRENCY unsigned char VarCyFromUI1(bIn, pcyOut)
short VarCyFromI2(sIn, pcyOut)
long VarCyFromI4(lIn, pcyOut)
float VarCyFromR4(fltIn, pcyOut)
double VarCyFromR8(dblIn, pcyOut)
CURRENCY None
DATE VarCyFromDate(dateIn, pcyOut)
OLECHAR FAR* VarCyFromStr(strIn, lcid, dwFlags, pcyOut)
IDispatch FAR* VarCyFromDisp(pdispIn, lcid, pcyOut)
BOOL VarCyFromBool(boolIn, pcyOut)
BSTR unsigned char VarBstrFromUI1(bVal, lcid, dwFlags, pbstrOut)
short VarBstrFromI2(iVal, lcid, dwFlags, pbstrOut)
long VarBstrFromI4(lIn, lcid, dwFlags, pbstrOut)
float VarBstrFromR4(fltIn, lcid, dwFlags, pbstrOut)
double VarBstrFromR8(dblIn, lcid, dwFlags, pbstrOut)
CURRENCY VarBstrFromCy(cyIn, lcid, dwFlags, pbstrOut)
DATE VarBstrFromDate(dateIn, lcid, dwFlags, pbstrOut)
OLECHAR FAR* None
IDispatch FAR* VarBstrFromDisp(pdispIn, lcid, dwFlags, pbstrOut)
BOOL VarBstrFromBool(boolIn, lcid, dwFlags, pbstrOut)
BOOL unsigned char VarBoolFromUI1(bIn, pboolOut)
short VarBoolFromI2(sIn, pboolOut)
long VarBoolFromI4(lIn, pboolOut)
float VarBoolFromR4(fltIn, pboolOut)
double VarBoolFromR8(dblIn, pboolOut)
CURRENCY VarBoolFromCy(cyIn, pboolOut)
DATE VarBoolFromDate(dateIn, pboolOut)
OLECHAR FAR* VarBoolFromStr(strIn, lcid, dwFlags, pboolOut)
IDispatch FAR* VarBoolFromDisp(pdispIn, lcid, pboolOut)
BOOL None

Parameters

bIn, sIn, lIn, fltIn, dblIn, cyIn, dateIn, strIn, pdispIn, boolIn
The value to coerce. These parameters have the following data types:
Parameter Data type
bIn unsigned char
sIn short
lIn long
fltIn float
dblIn double
cyIn CURRENCY
dateIn DATE
strIn OLECHAR FAR*
pdispIn IDispatch FAR*
boolIn BOOL

lcid
For conversions from string and VT_DISPATCH input, the LCID to use for the conversion. For a list of LCIDs, see "Supporting Multiple National Languages" in Chapter 2, "Exposing Automation Objects."
dwFlags
One or more of the following flags:
Flag Description
LOCALE_NOUSEROVERRIDE Uses the system default locale settings, rather than custom locale settings.
VAR_TIMEVALUEONLY Omits the date portion of a VT_DATE and returns only the time. Applies to conversions to or from dates.
VAR_DATEVALUEONLY Omits the time portion of a VT_DATE and returns only the time. Applies to conversions to or from dates.

pbOut, psOut, plOut, pfltOut, pdblOut, pcyOut, pstrOut, pdispOut, pboolOut
A pointer to the coerced value. These parameters have the following data types:
Parameter Data type
pbOut unsigned char
psOut short
plOut long
pfltOut float
pdblOut double
pcyOut CURRENCY
pdateOut DATE
pstrOut OLECHAR FAR*
pdispOut IDispatch FAR*
pboolOut BOOL

Return Value

The return value obtained from the returned HRESULT is one of the following.

Return value Meaning
S_OK Success.
DISP_E_BADVARTYPE The input parameter is not a valid type of variant.
DISP_E_OVERFLOW The data pointed to by the output parameter does not fit in the destination type.
DISP_E_TYPEMISMATCH The argument could not be coerced to the specified type.
E_INVALIDARG One of the arguments is invalid.
E_OUTOFMEMORY Memory could not be allocated for the conversion.