[PATCH 3/3] oleaut32: Handle preformatted strings in VarFormatCurrency().

Nikolay Sivov nsivov at codeweavers.com
Fri Feb 5 01:30:47 CST 2021


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46709
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/oleaut32/tests/varformat.c | 35 +++++++++++++++++++++++++++++++++
 dlls/oleaut32/varformat.c       | 15 ++++++++++++--
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/dlls/oleaut32/tests/varformat.c b/dlls/oleaut32/tests/varformat.c
index 54fc8a1841f..d1951b85a61 100644
--- a/dlls/oleaut32/tests/varformat.c
+++ b/dlls/oleaut32/tests/varformat.c
@@ -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();
 }
diff --git a/dlls/oleaut32/varformat.c b/dlls/oleaut32/varformat.c
index e88bf0bc365..8ed8f790d14 100644
--- a/dlls/oleaut32/varformat.c
+++ b/dlls/oleaut32/varformat.c
@@ -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);
-- 
2.30.0




More information about the wine-devel mailing list