2 * Copyright 2013 Piotr 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
20 #include "vbsregexp55.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
26 #define REGEXP_TID_LIST \
29 XDIID(MatchCollection2) \
33 #define XDIID(iface) iface ## _tid,
39 static REFIID tid_ids[] = {
40 #define XDIID(iface) &IID_I ## iface,
45 static ITypeLib *typelib;
46 static ITypeInfo *typeinfos[REGEXP_LAST_tid];
48 static HRESULT init_regexp_typeinfo(regexp_tid_t tid)
53 static const WCHAR vbscript_dll3W[] = {'v','b','s','c','r','i','p','t','.','d','l','l','\\','3',0};
56 hres = LoadTypeLib(vbscript_dll3W, &tl);
58 ERR("LoadRegTypeLib failed: %08x\n", hres);
62 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
69 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
71 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
75 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
76 ITypeInfo_Release(ti);
83 IRegExp2 IRegExp2_iface;
84 IRegExp IRegExp_iface;
89 static inline RegExp2 *impl_from_IRegExp2(IRegExp2 *iface)
91 return CONTAINING_RECORD(iface, RegExp2, IRegExp2_iface);
94 static HRESULT WINAPI RegExp2_QueryInterface(IRegExp2 *iface, REFIID riid, void **ppv)
96 RegExp2 *This = impl_from_IRegExp2(iface);
98 if(IsEqualGUID(riid, &IID_IUnknown)) {
99 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
100 *ppv = &This->IRegExp2_iface;
101 }else if(IsEqualGUID(riid, &IID_IDispatch)) {
102 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
103 *ppv = &This->IRegExp2_iface;
104 }else if(IsEqualGUID(riid, &IID_IRegExp2)) {
105 TRACE("(%p)->(IID_IRegExp2 %p)\n", This, ppv);
106 *ppv = &This->IRegExp2_iface;
107 }else if(IsEqualGUID(riid, &IID_IRegExp)) {
108 TRACE("(%p)->(IID_IRegExp %p)\n", This, ppv);
109 *ppv = &This->IRegExp_iface;
111 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
113 return E_NOINTERFACE;
116 IUnknown_AddRef((IUnknown*)*ppv);
120 static ULONG WINAPI RegExp2_AddRef(IRegExp2 *iface)
122 RegExp2 *This = impl_from_IRegExp2(iface);
123 LONG ref = InterlockedIncrement(&This->ref);
125 TRACE("(%p) ref=%d\n", This, ref);
130 static ULONG WINAPI RegExp2_Release(IRegExp2 *iface)
132 RegExp2 *This = impl_from_IRegExp2(iface);
133 LONG ref = InterlockedDecrement(&This->ref);
135 TRACE("(%p) ref=%d\n", This, ref);
144 static HRESULT WINAPI RegExp2_GetTypeInfoCount(IRegExp2 *iface, UINT *pctinfo)
146 RegExp2 *This = impl_from_IRegExp2(iface);
148 TRACE("(%p)->(%p)\n", This, pctinfo);
154 static HRESULT WINAPI RegExp2_GetTypeInfo(IRegExp2 *iface,
155 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
157 RegExp2 *This = impl_from_IRegExp2(iface);
158 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
162 static HRESULT WINAPI RegExp2_GetIDsOfNames(IRegExp2 *iface, REFIID riid,
163 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
165 RegExp2 *This = impl_from_IRegExp2(iface);
167 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid),
168 rgszNames, cNames, lcid, rgDispId);
170 return ITypeInfo_GetIDsOfNames(typeinfos[RegExp2_tid], rgszNames, cNames, rgDispId);
173 static HRESULT WINAPI RegExp2_Invoke(IRegExp2 *iface, DISPID dispIdMember,
174 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
175 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
177 RegExp2 *This = impl_from_IRegExp2(iface);
179 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
180 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
182 return ITypeInfo_Invoke(typeinfos[RegExp2_tid], iface, dispIdMember, wFlags,
183 pDispParams, pVarResult, pExcepInfo, puArgErr);
186 static HRESULT WINAPI RegExp2_get_Pattern(IRegExp2 *iface, BSTR *pPattern)
188 RegExp2 *This = impl_from_IRegExp2(iface);
189 FIXME("(%p)->(%p)\n", This, pPattern);
193 static HRESULT WINAPI RegExp2_put_Pattern(IRegExp2 *iface, BSTR pattern)
195 RegExp2 *This = impl_from_IRegExp2(iface);
196 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(pattern));
200 static HRESULT WINAPI RegExp2_get_IgnoreCase(IRegExp2 *iface, VARIANT_BOOL *pIgnoreCase)
202 RegExp2 *This = impl_from_IRegExp2(iface);
203 FIXME("(%p)->(%p)\n", This, pIgnoreCase);
207 static HRESULT WINAPI RegExp2_put_IgnoreCase(IRegExp2 *iface, VARIANT_BOOL ignoreCase)
209 RegExp2 *This = impl_from_IRegExp2(iface);
210 FIXME("(%p)->(%s)\n", This, ignoreCase ? "true" : "false");
214 static HRESULT WINAPI RegExp2_get_Global(IRegExp2 *iface, VARIANT_BOOL *pGlobal)
216 RegExp2 *This = impl_from_IRegExp2(iface);
217 FIXME("(%p)->(%p)\n", This, pGlobal);
221 static HRESULT WINAPI RegExp2_put_Global(IRegExp2 *iface, VARIANT_BOOL global)
223 RegExp2 *This = impl_from_IRegExp2(iface);
224 FIXME("(%p)->(%s)\n", This, global ? "true" : "false");
228 static HRESULT WINAPI RegExp2_get_Multiline(IRegExp2 *iface, VARIANT_BOOL *pMultiline)
230 RegExp2 *This = impl_from_IRegExp2(iface);
231 FIXME("(%p)->(%p)\n", This, pMultiline);
235 static HRESULT WINAPI RegExp2_put_Multiline(IRegExp2 *iface, VARIANT_BOOL multiline)
237 RegExp2 *This = impl_from_IRegExp2(iface);
238 FIXME("(%p)->(%s)\n", This, multiline ? "true" : "false");
242 static HRESULT WINAPI RegExp2_Execute(IRegExp2 *iface,
243 BSTR sourceString, IDispatch **ppMatches)
245 RegExp2 *This = impl_from_IRegExp2(iface);
246 FIXME("(%p)->(%s %p)\n", This, debugstr_w(sourceString), ppMatches);
250 static HRESULT WINAPI RegExp2_Test(IRegExp2 *iface, BSTR sourceString, VARIANT_BOOL *pMatch)
252 RegExp2 *This = impl_from_IRegExp2(iface);
253 FIXME("(%p)->(%s %p)\n", This, debugstr_w(sourceString), pMatch);
257 static HRESULT WINAPI RegExp2_Replace(IRegExp2 *iface, BSTR sourceString,
258 VARIANT replaceVar, BSTR *pDestString)
260 RegExp2 *This = impl_from_IRegExp2(iface);
261 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(sourceString),
262 debugstr_variant(&replaceVar), pDestString);
266 static const IRegExp2Vtbl RegExp2Vtbl = {
267 RegExp2_QueryInterface,
270 RegExp2_GetTypeInfoCount,
272 RegExp2_GetIDsOfNames,
276 RegExp2_get_IgnoreCase,
277 RegExp2_put_IgnoreCase,
280 RegExp2_get_Multiline,
281 RegExp2_put_Multiline,
287 static inline RegExp2 *impl_from_IRegExp(IRegExp *iface)
289 return CONTAINING_RECORD(iface, RegExp2, IRegExp_iface);
292 static HRESULT WINAPI RegExp_QueryInterface(IRegExp *iface, REFIID riid, void **ppv)
294 RegExp2 *This = impl_from_IRegExp(iface);
295 return IRegExp2_QueryInterface(&This->IRegExp2_iface, riid, ppv);
298 static ULONG WINAPI RegExp_AddRef(IRegExp *iface)
300 RegExp2 *This = impl_from_IRegExp(iface);
301 return IRegExp2_AddRef(&This->IRegExp2_iface);
304 static ULONG WINAPI RegExp_Release(IRegExp *iface)
306 RegExp2 *This = impl_from_IRegExp(iface);
307 return IRegExp2_Release(&This->IRegExp2_iface);
310 static HRESULT WINAPI RegExp_GetTypeInfoCount(IRegExp *iface, UINT *pctinfo)
312 RegExp2 *This = impl_from_IRegExp(iface);
313 return IRegExp2_GetTypeInfoCount(&This->IRegExp2_iface, pctinfo);
316 static HRESULT WINAPI RegExp_GetTypeInfo(IRegExp *iface,
317 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
319 RegExp2 *This = impl_from_IRegExp(iface);
320 return IRegExp2_GetTypeInfo(&This->IRegExp2_iface, iTInfo, lcid, ppTInfo);
323 static HRESULT WINAPI RegExp_GetIDsOfNames(IRegExp *iface, REFIID riid,
324 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
326 RegExp2 *This = impl_from_IRegExp(iface);
327 return IRegExp2_GetIDsOfNames(&This->IRegExp2_iface, riid, rgszNames, cNames, lcid, rgDispId);
330 static HRESULT WINAPI RegExp_Invoke(IRegExp *iface, DISPID dispIdMember,
331 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
332 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
334 RegExp2 *This = impl_from_IRegExp(iface);
335 return IRegExp2_Invoke(&This->IRegExp2_iface, dispIdMember, riid, lcid,
336 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
339 static HRESULT WINAPI RegExp_get_Pattern(IRegExp *iface, BSTR *pPattern)
341 RegExp2 *This = impl_from_IRegExp(iface);
342 return IRegExp2_get_Pattern(&This->IRegExp2_iface, pPattern);
345 static HRESULT WINAPI RegExp_put_Pattern(IRegExp *iface, BSTR pPattern)
347 RegExp2 *This = impl_from_IRegExp(iface);
348 return IRegExp2_put_Pattern(&This->IRegExp2_iface, pPattern);
351 static HRESULT WINAPI RegExp_get_IgnoreCase(IRegExp *iface, VARIANT_BOOL *pIgnoreCase)
353 RegExp2 *This = impl_from_IRegExp(iface);
354 return IRegExp2_get_IgnoreCase(&This->IRegExp2_iface, pIgnoreCase);
357 static HRESULT WINAPI RegExp_put_IgnoreCase(IRegExp *iface, VARIANT_BOOL pIgnoreCase)
359 RegExp2 *This = impl_from_IRegExp(iface);
360 return IRegExp2_put_IgnoreCase(&This->IRegExp2_iface, pIgnoreCase);
363 static HRESULT WINAPI RegExp_get_Global(IRegExp *iface, VARIANT_BOOL *pGlobal)
365 RegExp2 *This = impl_from_IRegExp(iface);
366 return IRegExp2_get_Global(&This->IRegExp2_iface, pGlobal);
369 static HRESULT WINAPI RegExp_put_Global(IRegExp *iface, VARIANT_BOOL pGlobal)
371 RegExp2 *This = impl_from_IRegExp(iface);
372 return IRegExp2_put_Global(&This->IRegExp2_iface, pGlobal);
375 static HRESULT WINAPI RegExp_Execute(IRegExp *iface,
376 BSTR sourceString, IDispatch **ppMatches)
378 RegExp2 *This = impl_from_IRegExp(iface);
379 return IRegExp2_Execute(&This->IRegExp2_iface, sourceString, ppMatches);
382 static HRESULT WINAPI RegExp_Test(IRegExp *iface, BSTR sourceString, VARIANT_BOOL *pMatch)
384 RegExp2 *This = impl_from_IRegExp(iface);
385 return IRegExp2_Test(&This->IRegExp2_iface, sourceString, pMatch);
388 static HRESULT WINAPI RegExp_Replace(IRegExp *iface, BSTR sourceString,
389 BSTR replaceString, BSTR *pDestString)
391 RegExp2 *This = impl_from_IRegExp(iface);
394 V_VT(&replace) = VT_BSTR;
395 V_BSTR(&replace) = replaceString;
396 return IRegExp2_Replace(&This->IRegExp2_iface, sourceString, replace, pDestString);
399 static IRegExpVtbl RegExpVtbl = {
400 RegExp_QueryInterface,
403 RegExp_GetTypeInfoCount,
405 RegExp_GetIDsOfNames,
409 RegExp_get_IgnoreCase,
410 RegExp_put_IgnoreCase,
418 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
423 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
425 hres = init_regexp_typeinfo(RegExp2_tid);
429 ret = heap_alloc_zero(sizeof(*ret));
431 return E_OUTOFMEMORY;
433 ret->IRegExp2_iface.lpVtbl = &RegExp2Vtbl;
434 ret->IRegExp_iface.lpVtbl = &RegExpVtbl;
438 hres = IRegExp2_QueryInterface(&ret->IRegExp2_iface, riid, ppv);
439 IRegExp2_Release(&ret->IRegExp2_iface);
443 void release_regexp_typelib(void)
447 for(i=0; i<REGEXP_LAST_tid; i++) {
449 ITypeInfo_Release(typeinfos[i]);
452 ITypeLib_Release(typelib);