Commit f7ef02bd authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

propsys: Partially implement VariantToString().

parent 0770ba61
......@@ -190,7 +190,7 @@
@ stub VariantToInt64WithDefault
@ stub VariantToPropVariant
@ stub VariantToStrRet
@ stub VariantToString
@ stdcall VariantToString(ptr ptr long)
@ stub VariantToStringAlloc
@ stub VariantToStringArray
@ stub VariantToStringArrayAlloc
......
......@@ -432,6 +432,38 @@ PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, const WCHAR *defau
}
/******************************************************************
* VariantToString (PROPSYS.@)
*/
HRESULT WINAPI VariantToString(REFVARIANT var, PWSTR ret, UINT cch)
{
WCHAR *str = NULL;
TRACE("%p, %p, %u.\n", var, ret, cch);
*ret = 0;
if (!cch)
return E_INVALIDARG;
if (V_VT(var) == VT_BSTR)
{
str = V_BSTR(var);
}
else
{
FIXME("Unsupported type %d.\n", V_VT(var));
return E_NOTIMPL;
}
if (wcslen(str) > cch - 1)
return STRSAFE_E_INSUFFICIENT_BUFFER;
wcscpy(ret, str);
return S_OK;
}
/******************************************************************
* PropVariantChangeType (PROPSYS.@)
*/
HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc,
......
......@@ -2277,6 +2277,35 @@ static void test_VariantToStringWithDefault(void)
SysFreeString(b);
}
static void test_VariantToString(void)
{
HRESULT hr;
VARIANT v;
WCHAR buff[64];
buff[0] = 1;
V_VT(&v) = VT_EMPTY;
hr = VariantToString(&v, buff, 64);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(!buff[0], "Unexpected buffer.\n");
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"test1");
buff[0] = 1;
hr = VariantToString(&v, buff, 0);
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
ok(!buff[0], "Unexpected buffer.\n");
hr = VariantToString(&v, buff, 5);
ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#lx.\n", hr);
hr = VariantToString(&v, buff, 6);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(!wcscmp(buff, L"test1"), "Unexpected string.\n");
VariantClear(&v);
}
START_TEST(propsys)
{
test_InitPropVariantFromGUIDAsString();
......@@ -2304,4 +2333,5 @@ START_TEST(propsys)
test_propertystore();
test_PSCreatePropertyStoreFromObject();
test_VariantToStringWithDefault();
test_VariantToString();
}
......@@ -95,6 +95,7 @@ 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);
PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, LPCWSTR pszDefault);
HRESULT WINAPI VariantToString(REFVARIANT var, PWSTR ret, UINT cch);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment