[PATCH 3/3] propsys: Implement PropVariantToBuffer().

Jactry Zeng jzeng at codeweavers.com
Thu Feb 14 21:27:01 CST 2019


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/propsys/propsys.spec    |  2 +-
 dlls/propsys/propvar.c       | 12 ++++++++++++
 dlls/propsys/tests/propsys.c | 33 +++++++++++++++++++++++++++++++++
 include/propvarutil.h        |  1 +
 4 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/dlls/propsys/propsys.spec b/dlls/propsys/propsys.spec
index d9347e27ae..8416b6dc74 100644
--- a/dlls/propsys/propsys.spec
+++ b/dlls/propsys/propsys.spec
@@ -111,7 +111,7 @@
 @ stub PropVariantToBooleanVector
 @ stub PropVariantToBooleanVectorAlloc
 @ stub PropVariantToBooleanWithDefault
-@ stub PropVariantToBuffer
+@ stdcall PropVariantToBuffer(ptr ptr long)
 @ stdcall PropVariantToDouble(ptr ptr)
 @ stub PropVariantToDoubleVector
 @ stub PropVariantToDoubleVectorAlloc
diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c
index 5950cc833b..6200e3e993 100644
--- a/dlls/propsys/propvar.c
+++ b/dlls/propsys/propvar.c
@@ -306,6 +306,18 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret)
     return hr;
 }
 
+HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb)
+{
+    TRACE("(%p, %p, %d)\n", propvarIn, ret, cb);
+
+    if(cb > propvarIn->u.caub.cElems)
+        return E_FAIL;
+
+    memcpy(ret, propvarIn->u.caub.pElems, cb);
+
+    return S_OK;
+}
+
 HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch)
 {
     HRESULT hr = S_OK;
diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c
index 05cff65151..740e349bfb 100644
--- a/dlls/propsys/tests/propsys.c
+++ b/dlls/propsys/tests/propsys.c
@@ -1406,6 +1406,38 @@ static void test_PropVariantToString(void)
     PropVariantClear(&propvar);
 }
 
+static void test_PropVariantToBuffer(void)
+{
+    PROPVARIANT propvar;
+    HRESULT hr;
+    UINT8 data[] = {1,2,3,4,5,6,7,8,9,10};
+    UINT8 buffer[256];
+
+    hr = InitPropVariantFromBuffer(data, 10, &propvar);
+    ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr);
+    hr = PropVariantToBuffer(&propvar, buffer, 10);
+    ok(hr == S_OK, "PropVariantToBuffer fail: 0x%08x.\n", hr);
+    ok(!memcmp(buffer, data, 10) && !buffer[10], "got wrong buffer.\n");
+    memset(buffer, 0, sizeof(buffer));
+    PropVariantClear(&propvar);
+
+    hr = InitPropVariantFromBuffer(data, 10, &propvar);
+    ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr);
+    hr = PropVariantToBuffer(&propvar, buffer, 11);
+    ok(hr == E_FAIL, "PropVariantToBuffer fail: 0x%08x.\n", hr);
+    ok(!buffer[0], "got wrong buffer.\n");
+    memset(buffer, 0, sizeof(buffer));
+    PropVariantClear(&propvar);
+
+    hr = InitPropVariantFromBuffer(data, 10, &propvar);
+    ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr);
+    hr = PropVariantToBuffer(&propvar, buffer, 9);
+    ok(hr == S_OK, "PropVariantToBuffer fail: 0x%08x.\n", hr);
+    ok(!memcmp(buffer, data, 9) && !buffer[9], "got wrong buffer.\n");
+    memset(buffer, 0, sizeof(buffer));
+    PropVariantClear(&propvar);
+}
+
 START_TEST(propsys)
 {
     test_PSStringFromPropertyKey();
@@ -1423,4 +1455,5 @@ START_TEST(propsys)
     test_InitPropVariantFromCLSID();
     test_PropVariantToDouble();
     test_PropVariantToString();
+    test_PropVariantToBuffer();
 }
diff --git a/include/propvarutil.h b/include/propvarutil.h
index 4fb12d87eb..a4eedefdb6 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 PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb);
 HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch);
 PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
 
-- 
2.20.1




More information about the wine-devel mailing list