Signed-off-by: Jactry Zeng <jzeng(a)codeweavers.com>
---
dlls/propsys/propsys.spec | 2 +-
dlls/propsys/propvar.c | 25 ++++++++++
dlls/propsys/tests/propsys.c | 91 ++++++++++++++++++++++++++++++++++++
include/propvarutil.h | 1 +
4 files changed, 118 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 396afbf050..ef490be978 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,30 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret)
return hr;
}
+HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch)
+{
+ HRESULT hr;
+ WCHAR *stringW = NULL;
+
+ TRACE("(%p, %p, %d)\n", propvarIn, ret, cch);
+
+ ret[0] = '\0';
+
+ if(!cch)
+ return E_INVALIDARG;
+
+ hr = PropVariantToStringAlloc(propvarIn, &stringW);
+ if(SUCCEEDED(hr))
+ {
+ if(lstrlenW(stringW) >= cch)
+ hr = STRSAFE_E_INSUFFICIENT_BUFFER;
+ lstrcpynW(ret, stringW, cch);
+ CoTaskMemFree(stringW);
+ }
+
+ 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 926dc3de71..299675db2e 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);
@@ -1310,6 +1311,95 @@ static void test_PropVariantToDouble(void)
ok(value == 8.0, "Unexpected value: %f.\n", value);
}
+static void test_PropVariantToString(void)
+{
+ PROPVARIANT propvar;
+ static CHAR string[] = "Wine";
+ 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));
+
+ 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(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
+ memset(bufferW, 0, sizeof(bufferW));
+
+ PropVariantInit(&propvar);
+ propvar.vt = VT_LPWSTR;
+ U(propvar).pwszVal = stringW;
+ hr = PropVariantToString(&propvar, bufferW, 4);
+ ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr);
+ ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n");
+ memset(bufferW, 0, sizeof(bufferW));
+
+ PropVariantInit(&propvar);
+ propvar.vt = VT_LPSTR;
+ U(propvar).pszVal = string;
+ hr = PropVariantToString(&propvar, bufferW, 4);
+ ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr);
+ ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n");
+ memset(bufferW, 0, sizeof(bufferW));
+
+ 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);
+}
+
START_TEST(propsys)
{
test_PSStringFromPropertyKey();
@@ -1326,4 +1416,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);
--
2.20.1