Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/msscript.c | 57 +++++++++++++++--------------- dlls/msscript.ocx/tests/msscript.c | 9 +++++ 2 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index 8fb127e..7385ce1 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -82,6 +82,9 @@ typedef struct ScriptHost { SCRIPTSTATE script_state; CLSID clsid;
+ unsigned int module_count; + ScriptModule **modules; + struct list named_items; } ScriptHost;
@@ -94,6 +97,7 @@ struct ScriptControl { IViewObjectEx IViewObjectEx_iface; IPointerInactive IPointerInactive_iface; IConnectionPointContainer IConnectionPointContainer_iface; + IScriptModuleCollection IScriptModuleCollection_iface; LONG ref; IOleClientSite *site; SIZEL extent; @@ -110,11 +114,6 @@ struct ScriptControl { IAdviseSink *view_sink; DWORD view_sink_flags;
- /* modules */ - unsigned int module_count; - ScriptModule **modules; - IScriptModuleCollection IScriptModuleCollection_iface; - ScriptHost *host; };
@@ -766,15 +765,15 @@ static ScriptModule *create_module(void) return module; }
-static void release_modules(ScriptControl *control) +static void release_modules(ScriptHost *host) { unsigned int i;
- for (i = 0; i < control->module_count; i++) - IScriptModule_Release(&control->modules[i]->IScriptModule_iface); + for (i = 0; i < host->module_count; i++) + IScriptModule_Release(&host->modules[i]->IScriptModule_iface);
- control->module_count = 0; - heap_free(control->modules); + host->module_count = 0; + heap_free(host->modules); }
static HRESULT WINAPI ScriptModuleCollection_QueryInterface(IScriptModuleCollection *iface, REFIID riid, void **ppv) @@ -896,8 +895,9 @@ static HRESULT WINAPI ScriptModuleCollection_get_Count(IScriptModuleCollection * TRACE("(%p)->(%p)\n", This, plCount);
if (!plCount) return E_POINTER; + if (!This->host) return E_FAIL;
- *plCount = This->module_count; + *plCount = This->host->module_count; return S_OK; }
@@ -947,6 +947,18 @@ static HRESULT init_script_host(const CLSID *clsid, ScriptHost **ret) host->clsid = *clsid; list_init(&host->named_items);
+ /* Alloc global module */ + host->modules = heap_alloc_zero(sizeof(*host->modules)); + if (!host->modules) return E_OUTOFMEMORY; + + host->modules[0] = create_module(); + if (!host->modules[0]) { + heap_free(host->modules); + heap_free(host); + return E_OUTOFMEMORY; + } + host->module_count = 1; + hr = CoCreateInstance(&host->clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&host->script); if (FAILED(hr)) { @@ -990,6 +1002,7 @@ static HRESULT init_script_host(const CLSID *clsid, ScriptHost **ret) return S_OK;
failed: + release_modules(host); release_script_engine(host); return hr; } @@ -1068,8 +1081,10 @@ static ULONG WINAPI ScriptControl_Release(IScriptControl *iface) if (This->site) IOleClientSite_Release(This->site); if (This->host) + { + release_modules(This->host); release_script_engine(This->host); - release_modules(This); + } heap_free(This); }
@@ -1159,7 +1174,6 @@ static HRESULT WINAPI ScriptControl_get_Language(IScriptControl *iface, BSTR *p) static HRESULT WINAPI ScriptControl_put_Language(IScriptControl *iface, BSTR language) { ScriptControl *This = impl_from_IScriptControl(iface); - ScriptModule **modules; CLSID clsid;
TRACE("(%p)->(%s)\n", This, debugstr_w(language)); @@ -1167,25 +1181,12 @@ static HRESULT WINAPI ScriptControl_put_Language(IScriptControl *iface, BSTR lan if (language && FAILED(CLSIDFromProgID(language, &clsid))) return CTL_E_INVALIDPROPERTYVALUE;
- /* Alloc new global module */ - modules = heap_alloc_zero(sizeof(*modules)); - if (!modules) return E_OUTOFMEMORY; - - modules[0] = create_module(); - if (!modules[0]) { - heap_free(modules); - return E_OUTOFMEMORY; - } - if (This->host) { + release_modules(This->host); release_script_engine(This->host); This->host = NULL; }
- release_modules(This); - This->modules = modules; - This->module_count = 1; - if (!language) return S_OK;
@@ -1332,7 +1333,7 @@ static HRESULT WINAPI ScriptControl_get_Modules(IScriptControl *iface, IScriptMo
TRACE("(%p)->(%p)\n", This, p);
- if (!This->module_count) return E_FAIL; + if (!This->host) return E_FAIL;
*p = &This->IScriptModuleCollection_iface; IScriptControl_AddRef(iface); diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index fbbe831..b6a5209 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -2414,7 +2414,16 @@ static void test_IScriptControl_get_Modules(void) ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr); ok(count == 1, "count is not 1, got %d.\n", count);
+ hr = IScriptControl_put_Language(sc, NULL); + ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr); + + hr = IScriptModuleCollection_get_Count(mods, &count); + ok(hr == E_FAIL, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr); + IScriptModuleCollection_Release(mods); + hr = IScriptControl_get_Modules(sc, &mods); + ok(hr == E_FAIL, "IScriptControl_get_Modules returned: 0x%08x.\n", hr); + IScriptControl_Release(sc);
/* custom script engine */