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

wshom.ocx: Implement get_Item() for IWshEnvironment.

parent 7311a9fc
......@@ -197,8 +197,22 @@ static HRESULT WINAPI WshEnvironment_Invoke(IWshEnvironment *iface, DISPID dispI
static HRESULT WINAPI WshEnvironment_get_Item(IWshEnvironment *iface, BSTR name, BSTR *value)
{
WshEnvironment *This = impl_from_IWshEnvironment(iface);
FIXME("(%p)->(%s %p): stub\n", This, debugstr_w(name), value);
return E_NOTIMPL;
DWORD len;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
if (!value)
return E_POINTER;
len = GetEnvironmentVariableW(name, NULL, 0);
*value = SysAllocStringLen(NULL, len);
if (!*value)
return E_OUTOFMEMORY;
if (len)
GetEnvironmentVariableW(name, *value, len+1);
return S_OK;
}
static HRESULT WINAPI WshEnvironment_put_Item(IWshEnvironment *iface, BSTR name, BSTR value)
......
......@@ -36,6 +36,9 @@ static void test_wshshell(void)
static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
static const WCHAR lnk1W[] = {'f','i','l','e','.','l','n','k',0};
static const WCHAR pathW[] = {'%','P','A','T','H','%',0};
static const WCHAR sysW[] = {'S','Y','S','T','E','M',0};
static const WCHAR path2W[] = {'P','A','T','H',0};
IWshEnvironment *env;
IWshShell3 *sh3;
IDispatchEx *dispex;
IWshCollection *coll;
......@@ -49,7 +52,7 @@ static void test_wshshell(void)
DISPPARAMS dp;
EXCEPINFO ei;
VARIANT arg, res;
BSTR str;
BSTR str, ret;
UINT err;
hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
......@@ -131,6 +134,43 @@ static void test_wshshell(void)
ok(hr == E_POINTER, "got 0x%08x\n", hr);
SysFreeString(str);
V_VT(&arg) = VT_BSTR;
V_BSTR(&arg) = SysAllocString(sysW);
hr = IWshShell3_get_Environment(sh3, &arg, &env);
ok(hr == S_OK, "got 0x%08x\n", hr);
VariantClear(&arg);
hr = IWshEnvironment_get_Item(env, NULL, NULL);
ok(hr == E_POINTER, "got 0x%08x\n", hr);
ret = (BSTR)0x1;
hr = IWshEnvironment_get_Item(env, NULL, &ret);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(ret && !*ret, "got %p\n", ret);
SysFreeString(ret);
/* invalid var name */
str = SysAllocString(lnk1W);
hr = IWshEnvironment_get_Item(env, str, NULL);
ok(hr == E_POINTER, "got 0x%08x\n", hr);
ret = NULL;
hr = IWshEnvironment_get_Item(env, str, &ret);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(ret && *ret == 0, "got %s\n", wine_dbgstr_w(ret));
SysFreeString(ret);
SysFreeString(str);
/* valid name */
str = SysAllocString(path2W);
hr = IWshEnvironment_get_Item(env, str, &ret);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(ret && *ret != 0, "got %s\n", wine_dbgstr_w(ret));
SysFreeString(ret);
SysFreeString(str);
IWshEnvironment_Release(env);
IWshCollection_Release(coll);
IDispatch_Release(disp);
IWshShell3_Release(sh3);
......
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