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"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(vbscript
);
32 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
34 static HINSTANCE vbscript_hinstance
;
36 static ITypeLib
*typelib
;
37 static ITypeInfo
*typeinfos
[LAST_tid
];
39 static REFIID tid_ids
[] = {
40 #define XDIID(iface) &DIID_ ## iface,
45 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
52 static const WCHAR vbscript_dll1W
[] = {'v','b','s','c','r','i','p','t','.','d','l','l','\\','1',0};
54 hres
= LoadTypeLib(vbscript_dll1W
, &tl
);
56 ERR("LoadRegTypeLib failed: %08x\n", hres
);
60 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
67 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
69 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
73 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
74 ITypeInfo_Release(ti
);
77 *typeinfo
= typeinfos
[tid
];
81 static void release_typelib(void)
88 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++) {
90 ITypeInfo_Release(typeinfos
[i
]);
93 ITypeLib_Release(typelib
);
96 const char *debugstr_variant(const VARIANT
*v
)
102 return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v
)));
110 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v
));
112 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v
));
114 return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v
));
116 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v
));
118 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v
)));
120 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v
));
122 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v
));
124 return wine_dbg_sprintf("{vt %d}", V_VT(v
));
128 #define MIN_BLOCK_SIZE 128
130 static inline DWORD
block_size(DWORD block
)
132 return MIN_BLOCK_SIZE
<< block
;
135 void vbsheap_init(vbsheap_t
*heap
)
137 memset(heap
, 0, sizeof(*heap
));
138 list_init(&heap
->custom_blocks
);
141 void *vbsheap_alloc(vbsheap_t
*heap
, size_t size
)
148 if(!heap
->block_cnt
) {
150 heap
->blocks
= heap_alloc(sizeof(void*));
155 tmp
= heap_alloc(block_size(0));
159 heap
->blocks
[0] = tmp
;
163 if(heap
->offset
+ size
<= block_size(heap
->last_block
)) {
164 tmp
= ((BYTE
*)heap
->blocks
[heap
->last_block
])+heap
->offset
;
165 heap
->offset
+= size
;
169 if(size
<= block_size(heap
->last_block
+1)) {
170 if(heap
->last_block
+1 == heap
->block_cnt
) {
171 tmp
= heap_realloc(heap
->blocks
, (heap
->block_cnt
+1)*sizeof(void*));
176 heap
->blocks
[heap
->block_cnt
] = heap_alloc(block_size(heap
->block_cnt
));
177 if(!heap
->blocks
[heap
->block_cnt
])
185 return heap
->blocks
[heap
->last_block
];
188 list
= heap_alloc(size
+ sizeof(struct list
));
192 list_add_head(&heap
->custom_blocks
, list
);
196 void vbsheap_free(vbsheap_t
*heap
)
201 while((iter
= list_next(&heap
->custom_blocks
, &heap
->custom_blocks
))) {
206 for(i
=0; i
< heap
->block_cnt
; i
++)
207 heap_free(heap
->blocks
[i
]);
208 heap_free(heap
->blocks
);
211 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
215 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
216 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
218 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
219 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
224 IUnknown_AddRef((IUnknown
*)*ppv
);
228 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
229 return E_NOINTERFACE
;
232 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
234 TRACE("(%p)\n", iface
);
238 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
240 TRACE("(%p)\n", iface
);
244 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
246 TRACE("(%p)->(%x)\n", iface
, fLock
);
250 static const IClassFactoryVtbl VBScriptFactoryVtbl
= {
251 ClassFactory_QueryInterface
,
253 ClassFactory_Release
,
254 VBScriptFactory_CreateInstance
,
255 ClassFactory_LockServer
258 static IClassFactory VBScriptFactory
= { &VBScriptFactoryVtbl
};
260 /******************************************************************
261 * DllMain (vbscript.@)
263 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
265 TRACE("(%p %d %p)\n", hInstDLL
, fdwReason
, lpv
);
269 case DLL_WINE_PREATTACH
:
270 return FALSE
; /* prefer native version */
271 case DLL_PROCESS_ATTACH
:
272 DisableThreadLibraryCalls(hInstDLL
);
273 vbscript_hinstance
= hInstDLL
;
275 case DLL_PROCESS_DETACH
:
282 /***********************************************************************
283 * DllGetClassObject (vbscript.@)
285 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
287 if(IsEqualGUID(&CLSID_VBScript
, rclsid
)) {
288 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid
), ppv
);
289 return IClassFactory_QueryInterface(&VBScriptFactory
, riid
, ppv
);
292 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
293 return CLASS_E_CLASSNOTAVAILABLE
;
296 /***********************************************************************
297 * DllCanUnloadNow (vbscript.@)
299 HRESULT WINAPI
DllCanUnloadNow(void)
304 /***********************************************************************
305 * DllRegisterServer (vbscript.@)
307 HRESULT WINAPI
DllRegisterServer(void)
310 return __wine_register_resources(vbscript_hinstance
);
313 /***********************************************************************
314 * DllUnregisterServer (vbscript.@)
316 HRESULT WINAPI
DllUnregisterServer(void)
319 return __wine_unregister_resources(vbscript_hinstance
);