Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/propsys/propsys.spec | 2 +- dlls/propsys/propvar.c | 38 ++++++++++++++++ dlls/propsys/tests/propsys.c | 87 ++++++++++++++++++++++++++++++++++++ include/propvarutil.h | 1 + 4 files changed, 127 insertions(+), 1 deletion(-)
diff --git a/dlls/propsys/propsys.spec b/dlls/propsys/propsys.spec index 9193f3664d..d9347e27ae 100644 --- a/dlls/propsys/propsys.spec +++ b/dlls/propsys/propsys.spec @@ -133,7 +133,7 @@ @ stub PropVariantToInt64VectorAlloc @ stub PropVariantToInt64WithDefault @ stub PropVariantToStrRet -@ stub PropVariantToString +@ stdcall PropVariantToString(ptr ptr long) @ stdcall PropVariantToStringAlloc(ptr ptr) @ stub PropVariantToStringVector @ stub PropVariantToStringVectorAlloc diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c index 0edf4621b3..22ea3251f8 100644 --- a/dlls/propsys/propvar.c +++ b/dlls/propsys/propvar.c @@ -34,6 +34,7 @@ #include "winuser.h" #include "shlobj.h" #include "propvarutil.h" +#include "strsafe.h"
#include "wine/debug.h" #include "wine/unicode.h" @@ -305,6 +306,43 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) return hr; }
+HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch) +{ + HRESULT hr = S_OK; + + TRACE("(%p, %p, %d): semi-stub\n", propvarIn, ret, cch); + + ret[0] = '\0'; + + if(!cch) + return E_INVALIDARG; + + switch(propvarIn->vt) + { + case VT_NULL: + case VT_EMPTY: + break; + case VT_BSTR: + case VT_LPWSTR: + if(lstrlenW(propvarIn->u.pwszVal) > cch) + hr = STRSAFE_E_INSUFFICIENT_BUFFER; + else + lstrcpyW(ret, propvarIn->u.pwszVal); + break; + case VT_LPSTR: + if(strlen(propvarIn->u.pszVal) > cch) + hr = STRSAFE_E_INSUFFICIENT_BUFFER; + else + MultiByteToWideChar(CP_ACP, 0, propvarIn->u.pszVal, -1, ret, cch); + break; + default: + FIXME("Unsupported conversion (%d)\n", propvarIn->vt); + hr = E_FAIL; + break; + } + return hr; +} + HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret) { WCHAR *res = NULL; diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c index a9c0a7730b..6d64afa355 100644 --- a/dlls/propsys/tests/propsys.c +++ b/dlls/propsys/tests/propsys.c @@ -32,6 +32,7 @@ #include "initguid.h" #include "propsys.h" #include "propvarutil.h" +#include "strsafe.h" #include "wine/test.h"
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); @@ -1304,6 +1305,91 @@ static void test_PropVariantToDouble(void) ok(value == 8.0, "Unexpected value: %f.\n", value); }
+static void test_PropVariantToString(void) +{ + PROPVARIANT propvar; + static CHAR string[] = {'T','e','s','t',0}; + static WCHAR stringW[] = {'W','i','n','e',0}; + WCHAR bufferW[256] = {0}; + HRESULT hr; + + PropVariantInit(&propvar); + propvar.vt = VT_EMPTY; + U(propvar).pwszVal = stringW; + bufferW[0] = 65; + hr = PropVariantToString(&propvar, bufferW, 0); + ok(hr == E_INVALIDARG, "PropVariantToString should fail: 0x%08x.\n", hr); + ok(!bufferW[0], "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_EMPTY; + U(propvar).pwszVal = stringW; + bufferW[0] = 65; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(!bufferW[0], "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_NULL; + U(propvar).pwszVal = stringW; + bufferW[0] = 65; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(!bufferW[0], "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_I4; + U(propvar).lVal = 22; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + todo_wine ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + todo_wine ok(!strcmp_wa(bufferW, "22"), "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_LPWSTR; + U(propvar).pwszVal = stringW; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(!lstrcmpW(bufferW, stringW), "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_LPSTR; + U(propvar).pszVal = string; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(!strcmp_wa(bufferW, string), "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_LPWSTR; + U(propvar).pwszVal = stringW; + hr = PropVariantToString(&propvar, bufferW, 1); + ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString should fail: 0x%08x.\n", hr); + ok(!bufferW[0], "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantClear(&propvar); + + PropVariantInit(&propvar); + propvar.vt = VT_BSTR; + propvar.u.bstrVal = SysAllocString(stringW); + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(!lstrcmpW(bufferW, stringW), "got wrong string: "%s".\n", wine_dbgstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + SysFreeString(propvar.u.bstrVal); + PropVariantClear(&propvar); +} + START_TEST(propsys) { test_PSStringFromPropertyKey(); @@ -1320,4 +1406,5 @@ START_TEST(propsys) test_PropVariantToStringWithDefault(); test_InitPropVariantFromCLSID(); test_PropVariantToDouble(); + test_PropVariantToString(); } diff --git a/include/propvarutil.h b/include/propvarutil.h index 80f081cbc3..4fb12d87eb 100644 --- a/include/propvarutil.h +++ b/include/propvarutil.h @@ -79,6 +79,7 @@ HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret); HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret); HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret); HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); +HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);