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
25 #include "vbscript_classes.h"
26 #include "vbsglobal.h"
27 #include "vbsregexp55.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
33 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
35 static HINSTANCE vbscript_hinstance;
37 static ITypeLib *typelib;
38 static ITypeInfo *typeinfos[LAST_tid];
40 static REFIID tid_ids[] = {
41 #define XDIID(iface) &DIID_ ## iface,
46 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
53 static const WCHAR vbscript_dll1W[] = {'v','b','s','c','r','i','p','t','.','d','l','l','\\','1',0};
55 hres = LoadTypeLib(vbscript_dll1W, &tl);
57 ERR("LoadRegTypeLib failed: %08x\n", hres);
61 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
68 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
70 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
74 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
75 ITypeInfo_Release(ti);
78 *typeinfo = typeinfos[tid];
82 static void release_typelib(void)
89 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++) {
91 ITypeInfo_Release(typeinfos[i]);
94 ITypeLib_Release(typelib);
97 const char *debugstr_variant(const VARIANT *v)
103 return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v)));
111 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
113 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
115 return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
117 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
119 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
121 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
123 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
125 return wine_dbg_sprintf("{vt %d}", V_VT(v));
129 #define MIN_BLOCK_SIZE 128
131 static inline DWORD block_size(DWORD block)
133 return MIN_BLOCK_SIZE << block;
136 void vbsheap_init(vbsheap_t *heap)
138 memset(heap, 0, sizeof(*heap));
139 list_init(&heap->custom_blocks);
142 void *vbsheap_alloc(vbsheap_t *heap, size_t size)
149 if(!heap->block_cnt) {
151 heap->blocks = heap_alloc(sizeof(void*));
156 tmp = heap_alloc(block_size(0));
160 heap->blocks[0] = tmp;
164 if(heap->offset + size <= block_size(heap->last_block)) {
165 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
166 heap->offset += size;
170 if(size <= block_size(heap->last_block+1)) {
171 if(heap->last_block+1 == heap->block_cnt) {
172 tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
177 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
178 if(!heap->blocks[heap->block_cnt])
186 return heap->blocks[heap->last_block];
189 list = heap_alloc(size + sizeof(struct list));
193 list_add_head(&heap->custom_blocks, list);
197 void vbsheap_free(vbsheap_t *heap)
202 while((iter = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
207 for(i=0; i < heap->block_cnt; i++)
208 heap_free(heap->blocks[i]);
209 heap_free(heap->blocks);
212 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
216 if(IsEqualGUID(&IID_IUnknown, riid)) {
217 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
219 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
220 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
225 IUnknown_AddRef((IUnknown*)*ppv);
229 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
230 return E_NOINTERFACE;
233 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
235 TRACE("(%p)\n", iface);
239 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
241 TRACE("(%p)\n", iface);
245 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
247 TRACE("(%p)->(%x)\n", iface, fLock);
251 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
252 ClassFactory_QueryInterface,
254 ClassFactory_Release,
255 VBScriptFactory_CreateInstance,
256 ClassFactory_LockServer
259 static IClassFactory VBScriptFactory = { &VBScriptFactoryVtbl };
261 static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl = {
262 ClassFactory_QueryInterface,
264 ClassFactory_Release,
265 VBScriptRegExpFactory_CreateInstance,
266 ClassFactory_LockServer
269 static IClassFactory VBScriptRegExpFactory = { &VBScriptRegExpFactoryVtbl };
271 /******************************************************************
272 * DllMain (vbscript.@)
274 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
276 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
280 case DLL_WINE_PREATTACH:
281 return FALSE; /* prefer native version */
282 case DLL_PROCESS_ATTACH:
283 DisableThreadLibraryCalls(hInstDLL);
284 vbscript_hinstance = hInstDLL;
286 case DLL_PROCESS_DETACH:
293 /***********************************************************************
294 * DllGetClassObject (vbscript.@)
296 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
298 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
299 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
300 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
301 }else if(IsEqualGUID(&CLSID_VBScriptRegExp, rclsid)) {
302 TRACE("(CLSID_VBScriptRegExp %s %p)\n", debugstr_guid(riid), ppv);
303 return IClassFactory_QueryInterface(&VBScriptRegExpFactory, riid, ppv);
306 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
307 return CLASS_E_CLASSNOTAVAILABLE;
310 /***********************************************************************
311 * DllCanUnloadNow (vbscript.@)
313 HRESULT WINAPI DllCanUnloadNow(void)
318 /***********************************************************************
319 * DllRegisterServer (vbscript.@)
321 HRESULT WINAPI DllRegisterServer(void)
324 return __wine_register_resources(vbscript_hinstance);
327 /***********************************************************************
328 * DllUnregisterServer (vbscript.@)
330 HRESULT WINAPI DllUnregisterServer(void)
333 return __wine_unregister_resources(vbscript_hinstance);