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
24 #include "vbscript_classes.h"
25 #include "vbsglobal.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
33 static HINSTANCE vbscript_hinstance;
35 static ITypeLib *typelib;
36 static ITypeInfo *typeinfos[LAST_tid];
38 static REFIID tid_ids[] = {
39 #define XDIID(iface) &DIID_ ## iface,
44 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
51 static const WCHAR vbscript_dll1W[] = {'v','b','s','c','r','i','p','t','.','d','l','l','\\','1',0};
53 hres = LoadTypeLib(vbscript_dll1W, &tl);
55 ERR("LoadRegTypeLib failed: %08x\n", hres);
59 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
66 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
68 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
72 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
73 ITypeInfo_Release(ti);
76 *typeinfo = typeinfos[tid];
80 static void release_typelib(void)
87 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++) {
89 ITypeInfo_Release(typeinfos[i]);
92 ITypeLib_Release(typelib);
95 const char *debugstr_variant(const VARIANT *v)
101 return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v)));
109 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
111 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
113 return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
115 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
117 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
119 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
121 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
123 return wine_dbg_sprintf("{vt %d}", V_VT(v));
127 #define MIN_BLOCK_SIZE 128
129 static inline DWORD block_size(DWORD block)
131 return MIN_BLOCK_SIZE << block;
134 void vbsheap_init(vbsheap_t *heap)
136 memset(heap, 0, sizeof(*heap));
137 list_init(&heap->custom_blocks);
140 void *vbsheap_alloc(vbsheap_t *heap, size_t size)
147 if(!heap->block_cnt) {
149 heap->blocks = heap_alloc(sizeof(void*));
154 tmp = heap_alloc(block_size(0));
158 heap->blocks[0] = tmp;
162 if(heap->offset + size <= block_size(heap->last_block)) {
163 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
164 heap->offset += size;
168 if(size <= block_size(heap->last_block+1)) {
169 if(heap->last_block+1 == heap->block_cnt) {
170 tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
175 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
176 if(!heap->blocks[heap->block_cnt])
184 return heap->blocks[heap->last_block];
187 list = heap_alloc(size + sizeof(struct list));
191 list_add_head(&heap->custom_blocks, list);
195 void vbsheap_free(vbsheap_t *heap)
200 while((iter = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
205 for(i=0; i < heap->block_cnt; i++)
206 heap_free(heap->blocks[i]);
207 heap_free(heap->blocks);
210 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
214 if(IsEqualGUID(&IID_IUnknown, riid)) {
215 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
217 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
218 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
223 IUnknown_AddRef((IUnknown*)*ppv);
227 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
228 return E_NOINTERFACE;
231 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
233 TRACE("(%p)\n", iface);
237 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
239 TRACE("(%p)\n", iface);
243 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
245 TRACE("(%p)->(%x)\n", iface, fLock);
249 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
250 ClassFactory_QueryInterface,
252 ClassFactory_Release,
253 VBScriptFactory_CreateInstance,
254 ClassFactory_LockServer
257 static IClassFactory VBScriptFactory = { &VBScriptFactoryVtbl };
259 /******************************************************************
260 * DllMain (vbscript.@)
262 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
264 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
268 case DLL_WINE_PREATTACH:
269 return FALSE; /* prefer native version */
270 case DLL_PROCESS_ATTACH:
271 DisableThreadLibraryCalls(hInstDLL);
272 vbscript_hinstance = hInstDLL;
274 case DLL_PROCESS_DETACH:
281 /***********************************************************************
282 * DllGetClassObject (vbscript.@)
284 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
286 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
287 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
288 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
291 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
292 return CLASS_E_CLASSNOTAVAILABLE;
295 /***********************************************************************
296 * DllCanUnloadNow (vbscript.@)
298 HRESULT WINAPI DllCanUnloadNow(void)
303 /***********************************************************************
304 * DllRegisterServer (vbscript.@)
306 HRESULT WINAPI DllRegisterServer(void)
309 return __wine_register_resources(vbscript_hinstance);
312 /***********************************************************************
313 * DllUnregisterServer (vbscript.@)
315 HRESULT WINAPI DllUnregisterServer(void)
318 return __wine_unregister_resources(vbscript_hinstance);