Commit 3fc11806 authored by Jactry Zeng's avatar Jactry Zeng Committed by Alexandre Julliard

propsys: Implement PropVariantToDouble().

parent 2e2fc550
......@@ -112,7 +112,7 @@
@ stub PropVariantToBooleanVectorAlloc
@ stub PropVariantToBooleanWithDefault
@ stub PropVariantToBuffer
@ stub PropVariantToDouble
@ stdcall PropVariantToDouble(ptr ptr)
@ stub PropVariantToDoubleVector
@ stub PropVariantToDoubleVectorAlloc
@ stub PropVariantToDoubleWithDefault
......
......@@ -129,6 +129,12 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits,
src_signed = *res < 0;
break;
}
case VT_R8:
{
src_signed = TRUE;
*res = pv->u.dblVal;
break;
}
default:
FIXME("unhandled vt %d\n", pv->vt);
return E_NOTIMPL;
......@@ -155,6 +161,18 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits,
return S_OK;
}
HRESULT WINAPI PropVariantToDouble(REFPROPVARIANT propvarIn, double *ret)
{
LONGLONG res;
HRESULT hr;
TRACE("(%p, %p)\n", propvarIn, ret);
hr = PROPVAR_ConvertNumber(propvarIn, 64, TRUE, &res);
if (SUCCEEDED(hr)) *ret = (double)res;
return hr;
}
HRESULT WINAPI PropVariantToInt16(REFPROPVARIANT propvarIn, SHORT *ret)
{
LONGLONG res;
......
......@@ -1248,6 +1248,62 @@ static void test_InitPropVariantFromCLSID(void)
PropVariantClear(&propvar);
}
static void test_PropVariantToDouble(void)
{
PROPVARIANT propvar;
double value;
HRESULT hr;
PropVariantInit(&propvar);
propvar.vt = VT_R8;
propvar.u.dblVal = 15.0;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 15.0, "Unexpected value: %f.\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_I4;
propvar.u.lVal = 123;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 123.0, "Unexpected value: %f.\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_I4;
propvar.u.lVal = -256;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == -256, "Unexpected value: %f\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_I8;
propvar.u.lVal = 65536;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 65536.0, "Unexpected value: %f.\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_I8;
propvar.u.lVal = -321;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 4294966975.0, "Unexpected value: %f.\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_UI4;
propvar.u.ulVal = 6;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 6.0, "Unexpected value: %f.\n", value);
PropVariantClear(&propvar);
propvar.vt = VT_UI8;
propvar.u.uhVal.QuadPart = 8;
hr = PropVariantToDouble(&propvar, &value);
ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr);
ok(value == 8.0, "Unexpected value: %f.\n", value);
}
START_TEST(propsys)
{
test_PSStringFromPropertyKey();
......@@ -1263,4 +1319,5 @@ START_TEST(propsys)
test_PropVariantToBoolean();
test_PropVariantToStringWithDefault();
test_InitPropVariantFromCLSID();
test_PropVariantToDouble();
}
......@@ -71,6 +71,7 @@ HRESULT WINAPI VariantToGUID(const VARIANT *pvar, GUID *guid);
INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2,
PROPVAR_COMPARE_UNIT uint, PROPVAR_COMPARE_FLAGS flags);
HRESULT WINAPI PropVariantToDouble(REFPROPVARIANT propvarIn, double *ret);
HRESULT WINAPI PropVariantToInt16(REFPROPVARIANT propvarIn, SHORT *ret);
HRESULT WINAPI PropVariantToInt32(REFPROPVARIANT propvarIn, LONG *ret);
HRESULT WINAPI PropVariantToInt64(REFPROPVARIANT propvarIn, LONGLONG *ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment