vbscript: Added interp_lt implementation.
[wine/multimedia.git] / dlls / vbscript / vbscript_main.c
blob43ab484735d1b7e0c7405bd38efe1e615ae30032
1 /*
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
19 #include "initguid.h"
21 #include "vbscript.h"
22 #include "objsafe.h"
23 #include "rpcproxy.h"
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)
36 if(!v)
37 return "(null)";
39 if(V_ISBYREF(v))
40 return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v)));
42 switch(V_VT(v)) {
43 case VT_EMPTY:
44 return "{VT_EMPTY}";
45 case VT_NULL:
46 return "{VT_NULL}";
47 case VT_I2:
48 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
49 case VT_I4:
50 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
51 case VT_UI4:
52 return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
53 case VT_R8:
54 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
55 case VT_BSTR:
56 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
57 case VT_DISPATCH:
58 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
59 case VT_BOOL:
60 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
61 default:
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)
81 struct list *list;
82 void *tmp;
84 size = (size+3)&~3;
86 if(!heap->block_cnt) {
87 if(!heap->blocks) {
88 heap->blocks = heap_alloc(sizeof(void*));
89 if(!heap->blocks)
90 return NULL;
93 tmp = heap_alloc(block_size(0));
94 if(!tmp)
95 return NULL;
97 heap->blocks[0] = tmp;
98 heap->block_cnt = 1;
101 if(heap->offset + size <= block_size(heap->last_block)) {
102 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
103 heap->offset += size;
104 return tmp;
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*));
110 if(!tmp)
111 return NULL;
113 heap->blocks = tmp;
114 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
115 if(!heap->blocks[heap->block_cnt])
116 return NULL;
118 heap->block_cnt++;
121 heap->last_block++;
122 heap->offset = size;
123 return heap->blocks[heap->last_block];
126 list = heap_alloc(size + sizeof(struct list));
127 if(!list)
128 return NULL;
130 list_add_head(&heap->custom_blocks, list);
131 return list+1;
134 void vbsheap_free(vbsheap_t *heap)
136 struct list *iter;
137 DWORD i;
139 while((iter = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
140 list_remove(iter);
141 heap_free(iter);
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)
151 *ppv = NULL;
153 if(IsEqualGUID(&IID_IUnknown, riid)) {
154 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
155 *ppv = iface;
156 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
157 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
158 *ppv = iface;
161 if(*ppv) {
162 IUnknown_AddRef((IUnknown*)*ppv);
163 return S_OK;
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);
173 return 2;
176 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
178 TRACE("(%p)\n", iface);
179 return 1;
182 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
184 TRACE("(%p)->(%x)\n", iface, fLock);
185 return S_OK;
188 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
189 ClassFactory_QueryInterface,
190 ClassFactory_AddRef,
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);
205 switch(fdwReason)
207 case DLL_WINE_PREATTACH:
208 return FALSE; /* prefer native version */
209 case DLL_PROCESS_ATTACH:
210 DisableThreadLibraryCalls(hInstDLL);
211 vbscript_hinstance = hInstDLL;
212 break;
215 return TRUE;
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)
237 return S_FALSE;
240 /***********************************************************************
241 * DllRegisterServer (vbscript.@)
243 HRESULT WINAPI DllRegisterServer(void)
245 TRACE("()\n");
246 return __wine_register_resources(vbscript_hinstance);
249 /***********************************************************************
250 * DllUnregisterServer (vbscript.@)
252 HRESULT WINAPI DllUnregisterServer(void)
254 TRACE("()\n");
255 return __wine_unregister_resources(vbscript_hinstance);