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"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
30 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 static HINSTANCE vbscript_hinstance;
34 const char *debugstr_variant(const VARIANT *v)
40 return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v)));
48 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
50 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
52 return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
54 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
56 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
58 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
60 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
62 return wine_dbg_sprintf("{vt %d}", V_VT(v));
66 #define MIN_BLOCK_SIZE 128
68 static inline DWORD block_size(DWORD block)
70 return MIN_BLOCK_SIZE << block;
73 void vbsheap_init(vbsheap_t *heap)
75 memset(heap, 0, sizeof(*heap));
76 list_init(&heap->custom_blocks);
79 void *vbsheap_alloc(vbsheap_t *heap, size_t size)
86 if(!heap->block_cnt) {
88 heap->blocks = heap_alloc(sizeof(void*));
93 tmp = heap_alloc(block_size(0));
97 heap->blocks[0] = tmp;
101 if(heap->offset + size <= block_size(heap->last_block)) {
102 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
103 heap->offset += size;
107 if(size <= block_size(heap->last_block+1)) {
108 if(heap->last_block+1 == heap->block_cnt) {
109 tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
114 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
115 if(!heap->blocks[heap->block_cnt])
123 return heap->blocks[heap->last_block];
126 list = heap_alloc(size + sizeof(struct list));
130 list_add_head(&heap->custom_blocks, list);
134 void vbsheap_free(vbsheap_t *heap)
139 while((iter = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
144 for(i=0; i < heap->block_cnt; i++)
145 heap_free(heap->blocks[i]);
146 heap_free(heap->blocks);
149 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
153 if(IsEqualGUID(&IID_IUnknown, riid)) {
154 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
156 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
157 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
162 IUnknown_AddRef((IUnknown*)*ppv);
166 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
167 return E_NOINTERFACE;
170 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
172 TRACE("(%p)\n", iface);
176 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
178 TRACE("(%p)\n", iface);
182 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
184 TRACE("(%p)->(%x)\n", iface, fLock);
188 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
189 ClassFactory_QueryInterface,
191 ClassFactory_Release,
192 VBScriptFactory_CreateInstance,
193 ClassFactory_LockServer
196 static IClassFactory VBScriptFactory = { &VBScriptFactoryVtbl };
198 /******************************************************************
199 * DllMain (vbscript.@)
201 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
203 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
207 case DLL_WINE_PREATTACH:
208 return FALSE; /* prefer native version */
209 case DLL_PROCESS_ATTACH:
210 DisableThreadLibraryCalls(hInstDLL);
211 vbscript_hinstance = hInstDLL;
218 /***********************************************************************
219 * DllGetClassObject (vbscript.@)
221 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
223 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
224 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
225 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
228 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
229 return CLASS_E_CLASSNOTAVAILABLE;
232 /***********************************************************************
233 * DllCanUnloadNow (vbscript.@)
235 HRESULT WINAPI DllCanUnloadNow(void)
240 /***********************************************************************
241 * DllRegisterServer (vbscript.@)
243 HRESULT WINAPI DllRegisterServer(void)
246 return __wine_register_resources(vbscript_hinstance);
249 /***********************************************************************
250 * DllUnregisterServer (vbscript.@)
252 HRESULT WINAPI DllUnregisterServer(void)
255 return __wine_unregister_resources(vbscript_hinstance);