mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-15 05:34:46 +00:00
propsys: Implement PropVariantToString().
Signed-off-by: Jactry Zeng <jzeng@codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
8db8c94155
commit
e0a829db99
|
@ -133,7 +133,7 @@
|
||||||
@ stub PropVariantToInt64VectorAlloc
|
@ stub PropVariantToInt64VectorAlloc
|
||||||
@ stub PropVariantToInt64WithDefault
|
@ stub PropVariantToInt64WithDefault
|
||||||
@ stub PropVariantToStrRet
|
@ stub PropVariantToStrRet
|
||||||
@ stub PropVariantToString
|
@ stdcall PropVariantToString(ptr ptr long)
|
||||||
@ stdcall PropVariantToStringAlloc(ptr ptr)
|
@ stdcall PropVariantToStringAlloc(ptr ptr)
|
||||||
@ stub PropVariantToStringVector
|
@ stub PropVariantToStringVector
|
||||||
@ stub PropVariantToStringVectorAlloc
|
@ stub PropVariantToStringVectorAlloc
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
#include "shlobj.h"
|
#include "shlobj.h"
|
||||||
#include "propvarutil.h"
|
#include "propvarutil.h"
|
||||||
|
#include "strsafe.h"
|
||||||
|
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
#include "wine/unicode.h"
|
#include "wine/unicode.h"
|
||||||
|
@ -305,6 +306,30 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret)
|
||||||
return hr;
|
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)
|
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret)
|
||||||
{
|
{
|
||||||
WCHAR *res = NULL;
|
WCHAR *res = NULL;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "initguid.h"
|
#include "initguid.h"
|
||||||
#include "propsys.h"
|
#include "propsys.h"
|
||||||
#include "propvarutil.h"
|
#include "propvarutil.h"
|
||||||
|
#include "strsafe.h"
|
||||||
#include "wine/test.h"
|
#include "wine/test.h"
|
||||||
|
|
||||||
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
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);
|
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)
|
START_TEST(propsys)
|
||||||
{
|
{
|
||||||
test_PSStringFromPropertyKey();
|
test_PSStringFromPropertyKey();
|
||||||
|
@ -1326,4 +1416,5 @@ START_TEST(propsys)
|
||||||
test_PropVariantToStringWithDefault();
|
test_PropVariantToStringWithDefault();
|
||||||
test_InitPropVariantFromCLSID();
|
test_InitPropVariantFromCLSID();
|
||||||
test_PropVariantToDouble();
|
test_PropVariantToDouble();
|
||||||
|
test_PropVariantToString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret);
|
||||||
HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret);
|
HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret);
|
||||||
HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret);
|
HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret);
|
||||||
HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret);
|
HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret);
|
||||||
|
HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch);
|
||||||
PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
|
PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
|
||||||
|
|
||||||
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
|
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
|
||||||
|
|
Loading…
Reference in a new issue