Nikolay Sivov : wshom.ocx: Implement get_Item() for IWshEnvironment.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jul 22 14:12:22 CDT 2014


Module: wine
Branch: master
Commit: ac65c3fb18d9c9be4aa43f373b4096bba991a0c9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ac65c3fb18d9c9be4aa43f373b4096bba991a0c9

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Jul 22 18:26:10 2014 +0400

wshom.ocx: Implement get_Item() for IWshEnvironment.

---

 dlls/wshom.ocx/shell.c       | 18 ++++++++++++++++--
 dlls/wshom.ocx/tests/wshom.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/dlls/wshom.ocx/shell.c b/dlls/wshom.ocx/shell.c
index 09b3fa0..b7b819a 100644
--- a/dlls/wshom.ocx/shell.c
+++ b/dlls/wshom.ocx/shell.c
@@ -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)
diff --git a/dlls/wshom.ocx/tests/wshom.c b/dlls/wshom.ocx/tests/wshom.c
index 5f6e79d..4c3581e 100644
--- a/dlls/wshom.ocx/tests/wshom.c
+++ b/dlls/wshom.ocx/tests/wshom.c
@@ -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);




More information about the wine-cvs mailing list