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 #define MIN_BLOCK_SIZE 128
36 static inline DWORD block_size(DWORD block)
38 return MIN_BLOCK_SIZE << block;
41 void vbsheap_init(vbsheap_t *heap)
43 memset(heap, 0, sizeof(*heap));
44 list_init(&heap->custom_blocks);
47 void *vbsheap_alloc(vbsheap_t *heap, size_t size)
54 if(!heap->block_cnt) {
56 heap->blocks = heap_alloc(sizeof(void*));
61 tmp = heap_alloc(block_size(0));
65 heap->blocks[0] = tmp;
69 if(heap->offset + size <= block_size(heap->last_block)) {
70 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
75 if(size <= block_size(heap->last_block+1)) {
76 if(heap->last_block+1 == heap->block_cnt) {
77 tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
82 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
83 if(!heap->blocks[heap->block_cnt])
91 return heap->blocks[heap->last_block];
94 list = heap_alloc(size + sizeof(struct list));
98 list_add_head(&heap->custom_blocks, list);
102 void vbsheap_free(vbsheap_t *heap)
107 while((iter = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
112 for(i=0; i < heap->block_cnt; i++)
113 heap_free(heap->blocks[i]);
114 heap_free(heap->blocks);
117 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
121 if(IsEqualGUID(&IID_IUnknown, riid)) {
122 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
124 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
125 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
130 IUnknown_AddRef((IUnknown*)*ppv);
134 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
135 return E_NOINTERFACE;
138 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
140 TRACE("(%p)\n", iface);
144 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
146 TRACE("(%p)\n", iface);
150 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
152 TRACE("(%p)->(%x)\n", iface, fLock);
156 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
157 ClassFactory_QueryInterface,
159 ClassFactory_Release,
160 VBScriptFactory_CreateInstance,
161 ClassFactory_LockServer
164 static IClassFactory VBScriptFactory = { &VBScriptFactoryVtbl };
166 /******************************************************************
167 * DllMain (vbscript.@)
169 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
171 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
175 case DLL_WINE_PREATTACH:
176 return FALSE; /* prefer native version */
177 case DLL_PROCESS_ATTACH:
178 DisableThreadLibraryCalls(hInstDLL);
179 vbscript_hinstance = hInstDLL;
186 /***********************************************************************
187 * DllGetClassObject (vbscript.@)
189 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
191 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
192 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
193 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
196 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
197 return CLASS_E_CLASSNOTAVAILABLE;
200 /***********************************************************************
201 * DllCanUnloadNow (vbscript.@)
203 HRESULT WINAPI DllCanUnloadNow(void)
208 /***********************************************************************
209 * DllRegisterServer (vbscript.@)
211 HRESULT WINAPI DllRegisterServer(void)
214 return __wine_register_resources(vbscript_hinstance);
217 /***********************************************************************
218 * DllUnregisterServer (vbscript.@)
220 HRESULT WINAPI DllUnregisterServer(void)
223 return __wine_unregister_resources(vbscript_hinstance);