oleaut32: Handle preformatted strings in VarFormatCurrency().

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46709
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit e26d6da8a9)
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
This commit is contained in:
Nikolay Sivov 2021-02-05 10:30:47 +03:00 committed by Michael Stefaniuc
parent 70a22fcb6e
commit 00fb915af4
2 changed files with 48 additions and 2 deletions

View File

@ -638,6 +638,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();
@ -645,4 +679,5 @@ START_TEST(varformat)
test_VarWeekdayName();
test_VarFormatFromTokens();
test_GetAltMonthNames();
test_VarFormatCurrency();
}

View File

@ -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);