📄 vartype.c
字号:
hRet = VarI8FromDec(pdecIn, &i64);
if (SUCCEEDED(hRet))
hRet = _VarUI4FromI8(i64, pulOut);
return hRet;
}
/************************************************************************
* VarUI4FromI8 (OLEAUT32.425)
*
* Convert a VT_I8 to a VT_UI4.
*
* PARAMS
* llIn [I] Source
* pulOut [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarUI4FromI8(LONG64 llIn, ULONG *pulOut)
{
return _VarUI4FromI8(llIn, pulOut);
}
/************************************************************************
* VarUI4FromUI8 (OLEAUT32.426)
*
* Convert a VT_UI8 to a VT_UI4.
*
* PARAMS
* ullIn [I] Source
* pulOut [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarUI4FromUI8(ULONG64 ullIn, ULONG *pulOut)
{
return _VarUI4FromUI8(ullIn, pulOut);
}
/* I8
*/
/************************************************************************
* VarI8FromUI1 (OLEAUT32.333)
*
* Convert a VT_UI1 to a VT_I8.
*
* PARAMS
* bIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromUI1(BYTE bIn, LONG64* pi64Out)
{
return _VarI8FromUI1(bIn, pi64Out);
}
/************************************************************************
* VarI8FromI2 (OLEAUT32.334)
*
* Convert a VT_I2 to a VT_I8.
*
* PARAMS
* sIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromI2(SHORT sIn, LONG64* pi64Out)
{
return _VarI8FromI2(sIn, pi64Out);
}
/************************************************************************
* VarI8FromR4 (OLEAUT32.335)
*
* Convert a VT_R4 to a VT_I8.
*
* PARAMS
* fltIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarI8FromR4(FLOAT fltIn, LONG64* pi64Out)
{
return VarI8FromR8(fltIn, pi64Out);
}
/************************************************************************
* VarI8FromR8 (OLEAUT32.336)
*
* Convert a VT_R8 to a VT_I8.
*
* PARAMS
* dblIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
*
* NOTES
* Only values that fit into 63 bits are accepted. Due to rounding issues,
* very high or low values will not be accurately converted.
*
* Numbers are rounded using Dutch rounding, as follows:
*
*| Fractional Part Sign Direction Example
*| --------------- ---- --------- -------
*| < 0.5 + Down 0.4 -> 0.0
*| < 0.5 - Up -0.4 -> 0.0
*| > 0.5 + Up 0.6 -> 1.0
*| < 0.5 - Up -0.6 -> -1.0
*| = 0.5 + Up/Down Down if even, Up if odd
*| = 0.5 - Up/Down Up if even, Down if odd
*
* This system is often used in supermarkets.
*/
HRESULT WINAPI VarI8FromR8(double dblIn, LONG64* pi64Out)
{
if ( dblIn < -4611686018427387904.0 || dblIn >= 4611686018427387904.0)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(LONG64, dblIn, *pi64Out);
return S_OK;
}
/************************************************************************
* VarI8FromCy (OLEAUT32.337)
*
* Convert a VT_CY to a VT_I8.
*
* PARAMS
* cyIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*
* NOTES
* All negative numbers are rounded down by 1, including those that are
* evenly divisible by 10000 (this is a Win32 bug that Wine mimics).
* Positive numbers are rounded using Dutch rounding: See VarI8FromR8()
* for details.
*/
HRESULT WINAPI VarI8FromCy(CY cyIn, LONG64* pi64Out)
{
*pi64Out = cyIn.int64 / CY_MULTIPLIER;
if (cyIn.int64 < 0)
(*pi64Out)--; /* Mimic Win32 bug */
else
{
cyIn.int64 -= *pi64Out * CY_MULTIPLIER; /* cyIn.s.Lo now holds fractional remainder */
if (cyIn.s.Lo > CY_HALF || (cyIn.s.Lo == CY_HALF && (*pi64Out & 0x1)))
(*pi64Out)++;
}
return S_OK;
}
/************************************************************************
* VarI8FromDate (OLEAUT32.338)
*
* Convert a VT_DATE to a VT_I8.
*
* PARAMS
* dateIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
* DISP_E_TYPEMISMATCH, if the type cannot be converted
*/
HRESULT WINAPI VarI8FromDate(DATE dateIn, LONG64* pi64Out)
{
return VarI8FromR8(dateIn, pi64Out);
}
/************************************************************************
* VarI8FromStr (OLEAUT32.339)
*
* Convert a VT_BSTR to a VT_I8.
*
* PARAMS
* strIn [I] Source
* lcid [I] LCID for the conversion
* dwFlags [I] Flags controlling the conversion (VAR_ flags from "oleauto.h")
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
* DISP_E_TYPEMISMATCH, if the type cannot be converted
*/
HRESULT WINAPI VarI8FromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, LONG64* pi64Out)
{
return VARIANT_NumberFromBstr(strIn, lcid, dwFlags, pi64Out, VT_I8);
}
/************************************************************************
* VarI8FromDisp (OLEAUT32.340)
*
* Convert a VT_DISPATCH to a VT_I8.
*
* PARAMS
* pdispIn [I] Source
* lcid [I] LCID for conversion
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
* DISP_E_TYPEMISMATCH, if the type cannot be converted
*/
HRESULT WINAPI VarI8FromDisp(IDispatch* pdispIn, LCID lcid, LONG64* pi64Out)
{
return VARIANT_FromDisp(pdispIn, lcid, pi64Out, VT_I8, 0);
}
/************************************************************************
* VarI8FromBool (OLEAUT32.341)
*
* Convert a VT_BOOL to a VT_I8.
*
* PARAMS
* boolIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromBool(VARIANT_BOOL boolIn, LONG64* pi64Out)
{
return VarI8FromI2(boolIn, pi64Out);
}
/************************************************************************
* VarI8FromI1 (OLEAUT32.342)
*
* Convert a VT_I1 to a VT_I8.
*
* PARAMS
* cIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromI1(signed char cIn, LONG64* pi64Out)
{
return _VarI8FromI1(cIn, pi64Out);
}
/************************************************************************
* VarI8FromUI2 (OLEAUT32.343)
*
* Convert a VT_UI2 to a VT_I8.
*
* PARAMS
* usIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromUI2(USHORT usIn, LONG64* pi64Out)
{
return _VarI8FromUI2(usIn, pi64Out);
}
/************************************************************************
* VarI8FromUI4 (OLEAUT32.344)
*
* Convert a VT_UI4 to a VT_I8.
*
* PARAMS
* ulIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarI8FromUI4(ULONG ulIn, LONG64* pi64Out)
{
return _VarI8FromUI4(ulIn, pi64Out);
}
/************************************************************************
* VarI8FromDec (OLEAUT32.345)
*
* Convert a VT_DECIMAL to a VT_I8.
*
* PARAMS
* pDecIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarI8FromDec(DECIMAL *pdecIn, LONG64* pi64Out)
{
if (!DEC_SCALE(pdecIn))
{
/* This decimal is just a 96 bit integer */
if (DEC_SIGN(pdecIn) & ~DECIMAL_NEG)
return E_INVALIDARG;
if (DEC_HI32(pdecIn) || DEC_MID32(pdecIn) & 0x80000000)
return DISP_E_OVERFLOW;
if (DEC_SIGN(pdecIn))
*pi64Out = -DEC_LO64(pdecIn);
else
*pi64Out = DEC_LO64(pdecIn);
return S_OK;
}
else
{
/* Decimal contains a floating point number */
HRESULT hRet;
double dbl;
hRet = VarR8FromDec(pdecIn, &dbl);
if (SUCCEEDED(hRet))
hRet = VarI8FromR8(dbl, pi64Out);
return hRet;
}
}
/************************************************************************
* VarI8FromUI8 (OLEAUT32.427)
*
* Convert a VT_UI8 to a VT_I8.
*
* PARAMS
* ullIn [I] Source
* pi64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarI8FromUI8(ULONG64 ullIn, LONG64* pi64Out)
{
return _VarI8FromUI8(ullIn, pi64Out);
}
/* UI8
*/
/************************************************************************
* VarUI8FromI8 (OLEAUT32.428)
*
* Convert a VT_I8 to a VT_UI8.
*
* PARAMS
* ulIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarUI8FromI8(LONG64 llIn, ULONG64* pui64Out)
{
return _VarUI8FromI8(llIn, pui64Out);
}
/************************************************************************
* VarUI8FromUI1 (OLEAUT32.429)
*
* Convert a VT_UI1 to a VT_UI8.
*
* PARAMS
* bIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarUI8FromUI1(BYTE bIn, ULONG64* pui64Out)
{
return _VarUI8FromUI1(bIn, pui64Out);
}
/************************************************************************
* VarUI8FromI2 (OLEAUT32.430)
*
* Convert a VT_I2 to a VT_UI8.
*
* PARAMS
* sIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* S_OK.
*/
HRESULT WINAPI VarUI8FromI2(SHORT sIn, ULONG64* pui64Out)
{
return _VarUI8FromI2(sIn, pui64Out);
}
/************************************************************************
* VarUI8FromR4 (OLEAUT32.431)
*
* Convert a VT_R4 to a VT_UI8.
*
* PARAMS
* fltIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
HRESULT WINAPI VarUI8FromR4(FLOAT fltIn, ULONG64* pui64Out)
{
return VarUI8FromR8(fltIn, pui64Out);
}
/************************************************************************
* VarUI8FromR8 (OLEAUT32.432)
*
* Convert a VT_R8 to a VT_UI8.
*
* PARAMS
* dblIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
*
* NOTES
* See VarI8FromR8() for details concerning rounding.
*/
HRESULT WINAPI VarUI8FromR8(double dblIn, ULONG64* pui64Out)
{
if (dblIn < -0.5 || dblIn > 1.844674407370955e19)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(ULONG64, dblIn, *pui64Out);
return S_OK;
}
/************************************************************************
* VarUI8FromCy (OLEAUT32.433)
*
* Convert a VT_CY to a VT_UI8.
*
* PARAMS
* cyIn [I] Source
* pui64Out [O] Destination
*
* RETURNS
* Success: S_OK.
* Failure: E_INVALIDARG, if the source value is invalid
* DISP_E_OVERFLOW, if the value will not fit in the destination
*
* NOTES
* Negative values >= -5000 will be converted to 0.
*/
HRESULT WINAPI VarUI8FromCy(CY cyIn, ULONG64* pui64Out)
{
if (cyIn.int64 < 0)
{
if (cyIn.int64 < -CY_HALF)
return DISP_E_OVERFLOW;
*pui64Out = 0;
}
else
{
*pui64Out = cyIn.int64 / CY_MULTIPLIER;
cyIn.int64 -= *pui64Out * CY_MULTIPLIER; /* cyIn.s.Lo now holds fractional remainder */
if (cyIn.s.Lo > CY_HALF || (cyIn.s.Lo == CY_HALF && (*pui64Out & 0x1)))
(*pui64Out)++;
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -