2 * Copyright 2011 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
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
25 static inline vbdisp_t *impl_from_IDispatchEx(IDispatchEx *iface)
27 return CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface);
30 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
32 vbdisp_t *This = impl_from_IDispatchEx(iface);
34 if(IsEqualGUID(&IID_IUnknown, riid)) {
35 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
36 *ppv = &This->IDispatchEx_iface;
37 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
38 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
39 *ppv = &This->IDispatchEx_iface;
40 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
41 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
42 *ppv = &This->IDispatchEx_iface;
44 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
49 IUnknown_AddRef((IUnknown*)*ppv);
53 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
55 vbdisp_t *This = impl_from_IDispatchEx(iface);
56 LONG ref = InterlockedIncrement(&This->ref);
58 TRACE("(%p) ref=%d\n", This, ref);
63 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
65 vbdisp_t *This = impl_from_IDispatchEx(iface);
66 LONG ref = InterlockedIncrement(&This->ref);
74 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
76 vbdisp_t *This = impl_from_IDispatchEx(iface);
78 TRACE("(%p)->(%p)\n", This, pctinfo);
84 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid,
87 vbdisp_t *This = impl_from_IDispatchEx(iface);
88 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
92 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
93 LPOLESTR *rgszNames, UINT cNames, LCID lcid,
96 vbdisp_t *This = impl_from_IDispatchEx(iface);
97 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
102 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
103 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
104 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
106 vbdisp_t *This = impl_from_IDispatchEx(iface);
107 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
108 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
112 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
114 vbdisp_t *This = impl_from_IDispatchEx(iface);
115 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
119 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
120 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
122 vbdisp_t *This = impl_from_IDispatchEx(iface);
123 FIXME("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
124 return DISP_E_MEMBERNOTFOUND;
127 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
129 vbdisp_t *This = impl_from_IDispatchEx(iface);
130 FIXME("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
134 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
136 vbdisp_t *This = impl_from_IDispatchEx(iface);
137 FIXME("(%p)->(%x)\n", This, id);
141 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
143 vbdisp_t *This = impl_from_IDispatchEx(iface);
144 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
148 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
150 vbdisp_t *This = impl_from_IDispatchEx(iface);
151 FIXME("(%p)->(%x %p)\n", This, id, pbstrName);
155 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
157 vbdisp_t *This = impl_from_IDispatchEx(iface);
158 FIXME("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
162 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
164 vbdisp_t *This = impl_from_IDispatchEx(iface);
165 FIXME("(%p)->(%p)\n", This, ppunk);
169 static IDispatchExVtbl DispatchExVtbl = {
170 DispatchEx_QueryInterface,
173 DispatchEx_GetTypeInfoCount,
174 DispatchEx_GetTypeInfo,
175 DispatchEx_GetIDsOfNames,
177 DispatchEx_GetDispID,
179 DispatchEx_DeleteMemberByName,
180 DispatchEx_DeleteMemberByDispID,
181 DispatchEx_GetMemberProperties,
182 DispatchEx_GetMemberName,
183 DispatchEx_GetNextDispID,
184 DispatchEx_GetNameSpaceParent
187 static HRESULT create_vbdisp(vbdisp_t **ret)
191 vbdisp = heap_alloc_zero(sizeof(*vbdisp));
193 return E_OUTOFMEMORY;
195 vbdisp->IDispatchEx_iface.lpVtbl = &DispatchExVtbl;
202 HRESULT init_global(script_ctx_t *ctx)
204 return create_vbdisp(&ctx->script_obj);
207 HRESULT disp_get_id(IDispatch *disp, BSTR name, DISPID *id)
212 if(disp->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl)
213 FIXME("properly handle builtin objects\n");
215 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
217 TRACE("unsing IDispatch\n");
218 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
221 hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseInsensitive, id);
222 IDispatchEx_Release(dispex);
226 HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, DISPPARAMS *dp, VARIANT *retv)
228 const WORD flags = DISPATCH_METHOD|(retv ? DISPATCH_PROPERTYGET : 0);
233 memset(&ei, 0, sizeof(ei));
235 V_VT(retv) = VT_EMPTY;
237 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
241 TRACE("using IDispatch\n");
242 return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei, &err);
245 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei, NULL /* CALLER_FIXME */);
246 IDispatchEx_Release(dispex);