ntdll: Add support for Win 10.
[wine/multimedia.git] / dlls / msscript.ocx / msscript.c
blobb4e933172b8fa604e26c1f9663548343c6aaab31
1 /*
2 * Copyright 2015 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "windows.h"
22 #include "initguid.h"
23 #include "ole2.h"
24 #include "rpcproxy.h"
25 #include "msscript.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msscript);
31 struct ScriptControl {
32 IScriptControl IScriptControl_iface;
33 LONG ref;
36 static HINSTANCE msscript_instance;
38 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
40 return HeapAlloc(GetProcessHeap(), 0, len);
43 static inline BOOL heap_free(void *mem)
45 return HeapFree(GetProcessHeap(), 0, mem);
48 typedef enum tid_t {
49 IScriptControl_tid,
50 LAST_tid
51 } tid_t;
53 static ITypeLib *typelib;
54 static ITypeInfo *typeinfos[LAST_tid];
56 static REFIID tid_ids[] = {
57 &IID_IScriptControl
60 static HRESULT load_typelib(void)
62 HRESULT hres;
63 ITypeLib *tl;
65 hres = LoadRegTypeLib(&LIBID_MSScriptControl, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
66 if(FAILED(hres)) {
67 ERR("LoadRegTypeLib failed: %08x\n", hres);
68 return hres;
71 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
72 ITypeLib_Release(tl);
73 return hres;
76 static HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
78 HRESULT hres;
80 if (!typelib)
81 hres = load_typelib();
82 if (!typelib)
83 return hres;
85 if(!typeinfos[tid]) {
86 ITypeInfo *ti;
88 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
89 if(FAILED(hres)) {
90 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
91 return hres;
94 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
95 ITypeInfo_Release(ti);
98 *typeinfo = typeinfos[tid];
99 ITypeInfo_AddRef(typeinfos[tid]);
100 return S_OK;
103 static void release_typelib(void)
105 unsigned i;
107 if(!typelib)
108 return;
110 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
111 if(typeinfos[i])
112 ITypeInfo_Release(typeinfos[i]);
114 ITypeLib_Release(typelib);
117 static inline ScriptControl *impl_from_IScriptControl(IScriptControl *iface)
119 return CONTAINING_RECORD(iface, ScriptControl, IScriptControl_iface);
122 static HRESULT WINAPI ScriptControl_QueryInterface(IScriptControl *iface, REFIID riid, void **ppv)
124 ScriptControl *This = impl_from_IScriptControl(iface);
126 if(IsEqualGUID(&IID_IUnknown, riid)) {
127 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
128 *ppv = &This->IScriptControl_iface;
129 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
130 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
131 *ppv = &This->IScriptControl_iface;
132 }else if(IsEqualGUID(&IID_IScriptControl, riid)) {
133 TRACE("(%p)->(IID_IScriptControl %p)\n", This, ppv);
134 *ppv = &This->IScriptControl_iface;
135 }else {
136 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
137 *ppv = NULL;
138 return E_NOINTERFACE;
141 IUnknown_AddRef((IUnknown*)*ppv);
142 return S_OK;
145 static ULONG WINAPI ScriptControl_AddRef(IScriptControl *iface)
147 ScriptControl *This = impl_from_IScriptControl(iface);
148 LONG ref = InterlockedIncrement(&This->ref);
150 TRACE("(%p) ref=%d\n", This, ref);
152 return ref;
155 static ULONG WINAPI ScriptControl_Release(IScriptControl *iface)
157 ScriptControl *This = impl_from_IScriptControl(iface);
158 LONG ref = InterlockedDecrement(&This->ref);
160 TRACE("(%p) ref=%d\n", This, ref);
162 if(!ref)
163 heap_free(This);
165 return ref;
168 static HRESULT WINAPI ScriptControl_GetTypeInfoCount(IScriptControl *iface, UINT *pctinfo)
170 ScriptControl *This = impl_from_IScriptControl(iface);
171 TRACE("(%p)->(%p)\n", This, pctinfo);
172 *pctinfo = 1;
173 return S_OK;
176 static HRESULT WINAPI ScriptControl_GetTypeInfo(IScriptControl *iface, UINT iTInfo,
177 LCID lcid, ITypeInfo **ppTInfo)
179 ScriptControl *This = impl_from_IScriptControl(iface);
180 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
181 return get_typeinfo(IScriptControl_tid, ppTInfo);
184 static HRESULT WINAPI ScriptControl_GetIDsOfNames(IScriptControl *iface, REFIID riid,
185 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
187 ScriptControl *This = impl_from_IScriptControl(iface);
188 ITypeInfo *typeinfo;
189 HRESULT hres;
191 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
193 hres = get_typeinfo(IScriptControl_tid, &typeinfo);
194 if(SUCCEEDED(hres)) {
195 hres = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
196 ITypeInfo_Release(typeinfo);
199 return hres;
202 static HRESULT WINAPI ScriptControl_Invoke(IScriptControl *iface, DISPID dispIdMember,
203 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
204 EXCEPINFO *pExcepInfo, UINT *puArgErr)
206 ScriptControl *This = impl_from_IScriptControl(iface);
207 ITypeInfo *typeinfo;
208 HRESULT hres;
210 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
211 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
213 hres = get_typeinfo(IScriptControl_tid, &typeinfo);
214 if(SUCCEEDED(hres)) {
215 hres = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
216 pDispParams, pVarResult, pExcepInfo, puArgErr);
217 ITypeInfo_Release(typeinfo);
220 return hres;
223 static HRESULT WINAPI ScriptControl_get_Language(IScriptControl *iface, BSTR *p)
225 ScriptControl *This = impl_from_IScriptControl(iface);
226 FIXME("(%p)->(%p)\n", This, p);
227 return E_NOTIMPL;
230 static HRESULT WINAPI ScriptControl_put_Language(IScriptControl *iface, BSTR language)
232 ScriptControl *This = impl_from_IScriptControl(iface);
233 FIXME("(%p)->(%s)\n", This, debugstr_w(language));
234 return E_NOTIMPL;
237 static HRESULT WINAPI ScriptControl_get_State(IScriptControl *iface, ScriptControlStates *p)
239 ScriptControl *This = impl_from_IScriptControl(iface);
240 FIXME("(%p)->(%p)\n", This, p);
241 return E_NOTIMPL;
244 static HRESULT WINAPI ScriptControl_put_State(IScriptControl *iface, ScriptControlStates state)
246 ScriptControl *This = impl_from_IScriptControl(iface);
247 FIXME("(%p)->(%x)\n", This, state);
248 return E_NOTIMPL;
251 static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwnd)
253 ScriptControl *This = impl_from_IScriptControl(iface);
254 FIXME("(%p)->(%x)\n", This, hwnd);
255 return E_NOTIMPL;
258 static HRESULT WINAPI ScriptControl_get_SitehWnd(IScriptControl *iface, LONG *p)
260 ScriptControl *This = impl_from_IScriptControl(iface);
261 FIXME("(%p)->(%p)\n", This, p);
262 return E_NOTIMPL;
265 static HRESULT WINAPI ScriptControl_get_Timeout(IScriptControl *iface, LONG *p)
267 ScriptControl *This = impl_from_IScriptControl(iface);
268 FIXME("(%p)->(%p)\n", This, p);
269 return E_NOTIMPL;
272 static HRESULT WINAPI ScriptControl_put_Timeout(IScriptControl *iface, LONG milliseconds)
274 ScriptControl *This = impl_from_IScriptControl(iface);
275 FIXME("(%p)->(%d)\n", This, milliseconds);
276 return E_NOTIMPL;
279 static HRESULT WINAPI ScriptControl_get_AllowUI(IScriptControl *iface, VARIANT_BOOL *p)
281 ScriptControl *This = impl_from_IScriptControl(iface);
282 FIXME("(%p)->(%p)\n", This, p);
283 return E_NOTIMPL;
286 static HRESULT WINAPI ScriptControl_put_AllowUI(IScriptControl *iface, VARIANT_BOOL allow_ui)
288 ScriptControl *This = impl_from_IScriptControl(iface);
289 FIXME("(%p)->(%x)\n", This, allow_ui);
290 return E_NOTIMPL;
293 static HRESULT WINAPI ScriptControl_get_UseSafeSubset(IScriptControl *iface, VARIANT_BOOL *p)
295 ScriptControl *This = impl_from_IScriptControl(iface);
296 FIXME("(%p)->(%p)\n", This, p);
297 return E_NOTIMPL;
300 static HRESULT WINAPI ScriptControl_put_UseSafeSubset(IScriptControl *iface, VARIANT_BOOL v)
302 ScriptControl *This = impl_from_IScriptControl(iface);
303 FIXME("(%p)->(%x)\n", This, v);
304 return E_NOTIMPL;
307 static HRESULT WINAPI ScriptControl_get_Modules(IScriptControl *iface, IScriptModuleCollection **p)
309 ScriptControl *This = impl_from_IScriptControl(iface);
310 FIXME("(%p)->(%p)\n", This, p);
311 return E_NOTIMPL;
314 static HRESULT WINAPI ScriptControl_get_Error(IScriptControl *iface, IScriptError **p)
316 ScriptControl *This = impl_from_IScriptControl(iface);
317 FIXME("(%p)->(%p)\n", This, p);
318 return E_NOTIMPL;
321 static HRESULT WINAPI ScriptControl_get_CodeObject(IScriptControl *iface, IDispatch **p)
323 ScriptControl *This = impl_from_IScriptControl(iface);
324 FIXME("(%p)->(%p)\n", This, p);
325 return E_NOTIMPL;
328 static HRESULT WINAPI ScriptControl_get_Procedures(IScriptControl *iface, IScriptProcedureCollection **p)
330 ScriptControl *This = impl_from_IScriptControl(iface);
331 FIXME("(%p)->(%p)\n", This, p);
332 return E_NOTIMPL;
335 static HRESULT WINAPI ScriptControl__AboutBox(IScriptControl *iface)
337 ScriptControl *This = impl_from_IScriptControl(iface);
338 FIXME("(%p)\n", This);
339 return E_NOTIMPL;
342 static HRESULT WINAPI ScriptControl_AddObject(IScriptControl *iface, BSTR name, IDispatch *object, VARIANT_BOOL add_members)
344 ScriptControl *This = impl_from_IScriptControl(iface);
345 FIXME("(%p)->(%s %p %x)\n", This, debugstr_w(name), object, add_members);
346 return E_NOTIMPL;
349 static HRESULT WINAPI ScriptControl_Reset(IScriptControl *iface)
351 ScriptControl *This = impl_from_IScriptControl(iface);
352 FIXME("(%p)\n", This);
353 return E_NOTIMPL;
356 static HRESULT WINAPI ScriptControl_AddCode(IScriptControl *iface, BSTR code)
358 ScriptControl *This = impl_from_IScriptControl(iface);
359 FIXME("(%p)->(%s)\n", This, debugstr_w(code));
360 return E_NOTIMPL;
363 static HRESULT WINAPI ScriptControl_Eval(IScriptControl *iface, BSTR expression, VARIANT *res)
365 ScriptControl *This = impl_from_IScriptControl(iface);
366 FIXME("(%p)->(%s %p)\n", This, debugstr_w(expression), res);
367 return E_NOTIMPL;
370 static HRESULT WINAPI ScriptControl_ExecuteStatement(IScriptControl *iface, BSTR statement)
372 ScriptControl *This = impl_from_IScriptControl(iface);
373 FIXME("(%p)->(%s)\n", This, debugstr_w(statement));
374 return E_NOTIMPL;
377 static HRESULT WINAPI ScriptControl_Run(IScriptControl *iface, BSTR procedure_name, SAFEARRAY **parameters, VARIANT *res)
379 ScriptControl *This = impl_from_IScriptControl(iface);
380 FIXME("(%p)->(%s %p %p)\n", This, debugstr_w(procedure_name), parameters, res);
381 return E_NOTIMPL;
384 static const IScriptControlVtbl ScriptControlVtbl = {
385 ScriptControl_QueryInterface,
386 ScriptControl_AddRef,
387 ScriptControl_Release,
388 ScriptControl_GetTypeInfoCount,
389 ScriptControl_GetTypeInfo,
390 ScriptControl_GetIDsOfNames,
391 ScriptControl_Invoke,
392 ScriptControl_get_Language,
393 ScriptControl_put_Language,
394 ScriptControl_get_State,
395 ScriptControl_put_State,
396 ScriptControl_put_SitehWnd,
397 ScriptControl_get_SitehWnd,
398 ScriptControl_get_Timeout,
399 ScriptControl_put_Timeout,
400 ScriptControl_get_AllowUI,
401 ScriptControl_put_AllowUI,
402 ScriptControl_get_UseSafeSubset,
403 ScriptControl_put_UseSafeSubset,
404 ScriptControl_get_Modules,
405 ScriptControl_get_Error,
406 ScriptControl_get_CodeObject,
407 ScriptControl_get_Procedures,
408 ScriptControl__AboutBox,
409 ScriptControl_AddObject,
410 ScriptControl_Reset,
411 ScriptControl_AddCode,
412 ScriptControl_Eval,
413 ScriptControl_ExecuteStatement,
414 ScriptControl_Run
417 static HRESULT WINAPI ScriptControl_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
419 ScriptControl *script_control;
420 HRESULT hres;
422 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
424 script_control = heap_alloc(sizeof(*script_control));
425 if(!script_control)
426 return E_OUTOFMEMORY;
428 script_control->IScriptControl_iface.lpVtbl = &ScriptControlVtbl;
429 script_control->ref = 1;
431 hres = IScriptControl_QueryInterface(&script_control->IScriptControl_iface, riid, ppv);
432 IScriptControl_Release(&script_control->IScriptControl_iface);
433 return hres;
436 /******************************************************************
437 * DllMain (msscript.ocx.@)
439 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
441 TRACE("(%p %d %p)\n", instance, reason, reserved);
443 switch(reason) {
444 case DLL_WINE_PREATTACH:
445 return FALSE; /* prefer native version */
446 case DLL_PROCESS_ATTACH:
447 msscript_instance = instance;
448 DisableThreadLibraryCalls(instance);
449 break;
450 case DLL_PROCESS_DETACH:
451 if(!reserved)
452 release_typelib();
453 break;
456 return TRUE;
459 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
461 *ppv = NULL;
463 if(IsEqualGUID(&IID_IUnknown, riid)) {
464 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
465 *ppv = iface;
466 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
467 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
468 *ppv = iface;
471 if(*ppv) {
472 IUnknown_AddRef((IUnknown*)*ppv);
473 return S_OK;
476 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
477 return E_NOINTERFACE;
480 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
482 TRACE("(%p)\n", iface);
483 return 2;
486 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
488 TRACE("(%p)\n", iface);
489 return 1;
492 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
494 TRACE("(%p)->(%x)\n", iface, fLock);
495 return S_OK;
498 static const IClassFactoryVtbl ScriptControlFactoryVtbl = {
499 ClassFactory_QueryInterface,
500 ClassFactory_AddRef,
501 ClassFactory_Release,
502 ScriptControl_CreateInstance,
503 ClassFactory_LockServer
506 static IClassFactory ScriptControlFactory = { &ScriptControlFactoryVtbl };
508 /***********************************************************************
509 * DllGetClassObject (msscript.ocx.@)
511 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
513 if(IsEqualGUID(&CLSID_ScriptControl, rclsid)) {
514 TRACE("(CLSID_ScriptControl %s %p)\n", debugstr_guid(riid), ppv);
515 return IClassFactory_QueryInterface(&ScriptControlFactory, riid, ppv);
518 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
519 return CLASS_E_CLASSNOTAVAILABLE;
522 /***********************************************************************
523 * DllCanUnloadNow (msscript.ocx.@)
525 HRESULT WINAPI DllCanUnloadNow(void)
527 TRACE("\n");
528 return S_FALSE;
531 /***********************************************************************
532 * DllRegisterServer (msscript.ocx.@)
534 HRESULT WINAPI DllRegisterServer(void)
536 TRACE("()\n");
537 return __wine_register_resources(msscript_instance);
540 /***********************************************************************
541 * DllUnregisterServer (msscript.ocx.@)
543 HRESULT WINAPI DllUnregisterServer(void)
545 TRACE("()\n");
546 return __wine_unregister_resources(msscript_instance);