Commit e26d6da8 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

oleaut32: Handle preformatted strings in VarFormatCurrency().

parent 74f63545
......@@ -625,6 +625,40 @@ static void test_GetAltMonthNames(void)
ok(str != NULL, "Got %p\n", str);
}
static void test_VarFormatCurrency(void)
{
HRESULT hr;
VARIANT in;
BSTR str, str2;
V_CY(&in).int64 = 0;
V_VT(&in) = VT_CY;
hr = VarFormatCurrency(&in, 3, -2, -2, -2, 0, &str);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
V_VT(&in) = VT_BSTR;
V_BSTR(&in) = str;
hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(lstrcmpW(str, str2), "Expected different string.\n");
SysFreeString(str2);
V_VT(&in) = VT_BSTR | VT_BYREF;
V_BSTRREF(&in) = &str;
hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(lstrcmpW(str, str2), "Expected different string.\n");
SysFreeString(str);
SysFreeString(str2);
V_VT(&in) = VT_BSTR;
V_BSTR(&in) = SysAllocString(L"test");
hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr);
VariantClear(&in);
}
START_TEST(varformat)
{
test_VarFormatNumber();
......@@ -632,4 +666,5 @@ START_TEST(varformat)
test_VarWeekdayName();
test_VarFormatFromTokens();
test_GetAltMonthNames();
test_VarFormatCurrency();
}
......@@ -2401,6 +2401,7 @@ HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading,
{
HRESULT hRet;
VARIANT vStr;
CY cy;
TRACE("(%s,%d,%d,%d,%d,0x%08x,%p)\n", debugstr_variant(pVarIn), nDigits, nLeading,
nParens, nGrouping, dwFlags, pbstrOut);
......@@ -2410,8 +2411,18 @@ HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading,
*pbstrOut = NULL;
V_VT(&vStr) = VT_EMPTY;
hRet = VariantCopyInd(&vStr, pVarIn);
if (V_VT(pVarIn) == VT_BSTR || V_VT(pVarIn) == (VT_BSTR | VT_BYREF))
{
hRet = VarCyFromStr(V_ISBYREF(pVarIn) ? *V_BSTRREF(pVarIn) : V_BSTR(pVarIn), LOCALE_USER_DEFAULT, 0, &cy);
if (FAILED(hRet)) return hRet;
V_VT(&vStr) = VT_CY;
V_CY(&vStr) = cy;
}
else
{
V_VT(&vStr) = VT_EMPTY;
hRet = VariantCopyInd(&vStr, pVarIn);
}
if (SUCCEEDED(hRet))
hRet = VariantChangeTypeEx(&vStr, &vStr, LOCALE_USER_DEFAULT, 0, VT_BSTR);
......
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