[PATCH v2 4/4] propsys: Implement PropVariantToBuffer().
Nikolay Sivov
nsivov at codeweavers.com
Fri Feb 15 02:26:05 CST 2019
On 2/15/19 11:16 AM, Jactry Zeng wrote:
> Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
> ---
> dlls/propsys/propsys.spec | 2 +-
> dlls/propsys/propvar.c | 13 ++++++++++++
> dlls/propsys/tests/propsys.c | 39 ++++++++++++++++++++++++++++++++++++
> include/propvarutil.h | 1 +
> 4 files changed, 54 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 988cf81971..5817d502f3 100644
> --- a/dlls/propsys/propvar.c
> +++ b/dlls/propsys/propvar.c
> @@ -306,6 +306,19 @@ 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;
> +}
This one should probably check variant type.
> +
> +
> HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch)
> {
> HRESULT hr;
> diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c
> index 059b622544..1e5e88bc3b 100644
> --- a/dlls/propsys/tests/propsys.c
> +++ b/dlls/propsys/tests/propsys.c
> @@ -1407,6 +1407,44 @@ static void test_PropVariantToString(void)
> SysFreeString(propvar.u.bstrVal);
> }
>
> +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, NULL, 0); /* crash when cb isn't zero */
> + ok(hr == S_OK, "PropVariantToBuffer fail: 0x%08x.\n", hr);
> + PropVariantClear(&propvar);
> +
> + 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();
> @@ -1424,4 +1462,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);
>
More information about the wine-devel
mailing list