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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msscript
);
31 struct ScriptControl
{
32 IScriptControl IScriptControl_iface
;
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
);
53 static ITypeLib
*typelib
;
54 static ITypeInfo
*typeinfos
[LAST_tid
];
56 static REFIID tid_ids
[] = {
60 static HRESULT
load_typelib(void)
65 hres
= LoadRegTypeLib(&LIBID_MSScriptControl
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
67 ERR("LoadRegTypeLib failed: %08x\n", hres
);
71 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
76 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
81 hres
= load_typelib();
88 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
90 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
94 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
95 ITypeInfo_Release(ti
);
98 *typeinfo
= typeinfos
[tid
];
99 ITypeInfo_AddRef(typeinfos
[tid
]);
103 static void release_typelib(void)
110 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*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
;
136 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
138 return E_NOINTERFACE
;
141 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
168 static HRESULT WINAPI
ScriptControl_GetTypeInfoCount(IScriptControl
*iface
, UINT
*pctinfo
)
170 ScriptControl
*This
= impl_from_IScriptControl(iface
);
171 TRACE("(%p)->(%p)\n", This
, pctinfo
);
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
);
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
);
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
);
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
);
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
);
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
));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
335 static HRESULT WINAPI
ScriptControl__AboutBox(IScriptControl
*iface
)
337 ScriptControl
*This
= impl_from_IScriptControl(iface
);
338 FIXME("(%p)\n", This
);
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
);
349 static HRESULT WINAPI
ScriptControl_Reset(IScriptControl
*iface
)
351 ScriptControl
*This
= impl_from_IScriptControl(iface
);
352 FIXME("(%p)\n", This
);
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
));
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
);
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
));
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
);
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
,
411 ScriptControl_AddCode
,
413 ScriptControl_ExecuteStatement
,
417 static HRESULT WINAPI
ScriptControl_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
419 ScriptControl
*script_control
;
422 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
424 script_control
= heap_alloc(sizeof(*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
);
436 /******************************************************************
437 * DllMain (msscript.ocx.@)
439 BOOL WINAPI
DllMain(HINSTANCE instance
, DWORD reason
, void *reserved
)
441 TRACE("(%p %d %p)\n", instance
, reason
, reserved
);
444 case DLL_WINE_PREATTACH
:
445 return FALSE
; /* prefer native version */
446 case DLL_PROCESS_ATTACH
:
447 msscript_instance
= instance
;
448 DisableThreadLibraryCalls(instance
);
450 case DLL_PROCESS_DETACH
:
459 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
463 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
464 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
466 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
467 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
472 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
486 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
488 TRACE("(%p)\n", iface
);
492 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
494 TRACE("(%p)->(%x)\n", iface
, fLock
);
498 static const IClassFactoryVtbl ScriptControlFactoryVtbl
= {
499 ClassFactory_QueryInterface
,
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)
531 /***********************************************************************
532 * DllRegisterServer (msscript.ocx.@)
534 HRESULT WINAPI
DllRegisterServer(void)
537 return __wine_register_resources(msscript_instance
);
540 /***********************************************************************
541 * DllUnregisterServer (msscript.ocx.@)
543 HRESULT WINAPI
DllUnregisterServer(void)
546 return __wine_unregister_resources(msscript_instance
);