From 173515e7333e6c06405c2999f93825aa96c82452 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Fri, 1 Jul 2016 07:56:55 +0000 Subject: [PATCH] propsys: Support VT_LPWSTR in PropVariantChangeType. Signed-off-by: Alistair Leslie-Hughes Signed-off-by: Alexandre Julliard --- dlls/propsys/propvar.c | 14 ++++++++++++++ dlls/propsys/tests/propsys.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c index 7b1cec53198..002555e4891 100644 --- a/dlls/propsys/propvar.c +++ b/dlls/propsys/propvar.c @@ -257,6 +257,9 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p FIXME("(%p, %p, %d, %d, %d): semi-stub!\n", ppropvarDest, propvarSrc, propvarSrc->vt, flags, vt); + if(vt == propvarSrc->vt) + return PropVariantCopy(ppropvarDest, propvarSrc); + switch (vt) { case VT_I2: @@ -325,6 +328,17 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p } return hr; } + case VT_LPWSTR: + { + WCHAR *res; + hr = PropVariantToStringAlloc(propvarSrc, &res); + if (SUCCEEDED(hr)) + { + ppropvarDest->vt = VT_LPWSTR; + ppropvarDest->u.pwszVal = res; + } + return hr; + } } switch (propvarSrc->vt) diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c index d7d83d830ab..b6586785ec0 100644 --- a/dlls/propsys/tests/propsys.c +++ b/dlls/propsys/tests/propsys.c @@ -891,6 +891,42 @@ static void test_intconversions(void) ok(llval == -7, "got wrong value %s\n", debugstr_longlong(llval)); } +static void test_PropVariantChangeType_LPWSTR(void) +{ + PROPVARIANT dest, src; + HRESULT hr; + + PropVariantInit(&dest); + + src.vt = VT_NULL; + hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); + ok(hr == S_OK, "hr=%x\n", hr); + ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); + ok(!lstrcmpW(dest.u.pwszVal, emptyW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + PropVariantClear(&dest); + PropVariantClear(&src); + + src.vt = VT_LPSTR; + src.u.pszVal = CoTaskMemAlloc(strlen(topic)+1); + strcpy(src.u.pszVal, topic); + hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); + ok(hr == S_OK, "hr=%x\n", hr); + ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); + ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + PropVariantClear(&dest); + PropVariantClear(&src); + + src.vt = VT_LPWSTR; + src.u.pwszVal = CoTaskMemAlloc( (lstrlenW(topicW)+1) * sizeof(WCHAR)); + lstrcpyW(src.u.pwszVal, topicW); + hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); + ok(hr == S_OK, "hr=%x\n", hr); + ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); + ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + PropVariantClear(&dest); + PropVariantClear(&src); +} + START_TEST(propsys) { test_PSStringFromPropertyKey(); @@ -902,4 +938,5 @@ START_TEST(propsys) test_PropVariantToStringAlloc(); test_PropVariantCompare(); test_intconversions(); + test_PropVariantChangeType_LPWSTR(); }