windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / dlls / jscript / jscript_main.c
blobecbb5a713ab85c458bcc04d27d77b161eabf1d17
1 /*
2 * Copyright 2008 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 "jscript.h"
23 #include "winreg.h"
24 #include "advpub.h"
25 #include "activaut.h"
26 #include "objsafe.h"
27 #include "mshtmhst.h"
28 #include "rpcproxy.h"
29 #include "jscript_classes.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
35 LONG module_ref = 0;
37 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
39 HINSTANCE jscript_hinstance;
40 static DWORD jscript_tls;
41 static ITypeInfo *dispatch_typeinfo;
43 static int weak_refs_compare(const void *key, const struct rb_entry *entry)
45 const struct weak_refs_entry *weak_refs_entry = RB_ENTRY_VALUE(entry, const struct weak_refs_entry, entry);
46 ULONG_PTR a = (ULONG_PTR)key, b = (ULONG_PTR)LIST_ENTRY(weak_refs_entry->list.next, struct weakmap_entry, weak_refs_entry)->key;
47 return (a > b) - (a < b);
50 struct thread_data *get_thread_data(void)
52 struct thread_data *thread_data = TlsGetValue(jscript_tls);
54 if(!thread_data) {
55 thread_data = calloc(1, sizeof(struct thread_data));
56 if(!thread_data)
57 return NULL;
58 thread_data->thread_id = GetCurrentThreadId();
59 list_init(&thread_data->objects);
60 rb_init(&thread_data->weak_refs, weak_refs_compare);
61 TlsSetValue(jscript_tls, thread_data);
64 thread_data->ref++;
65 return thread_data;
68 void release_thread_data(struct thread_data *thread_data)
70 if(--thread_data->ref)
71 return;
73 free(thread_data);
74 TlsSetValue(jscript_tls, NULL);
77 HRESULT get_dispatch_typeinfo(ITypeInfo **out)
79 ITypeInfo *typeinfo;
80 ITypeLib *typelib;
81 HRESULT hr;
83 if (!dispatch_typeinfo)
85 hr = LoadRegTypeLib(&IID_StdOle, STDOLE_MAJORVERNUM, STDOLE_MINORVERNUM, STDOLE_LCID, &typelib);
86 if (FAILED(hr)) return hr;
88 hr = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IDispatch, &typeinfo);
89 ITypeLib_Release(typelib);
90 if (FAILED(hr)) return hr;
92 if (InterlockedCompareExchangePointer((void**)&dispatch_typeinfo, typeinfo, NULL))
93 ITypeInfo_Release(typeinfo);
96 *out = dispatch_typeinfo;
97 return S_OK;
100 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
102 *ppv = NULL;
104 if(IsEqualGUID(&IID_IUnknown, riid)) {
105 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
106 *ppv = iface;
107 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
108 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
109 *ppv = iface;
112 if(*ppv) {
113 IUnknown_AddRef((IUnknown*)*ppv);
114 return S_OK;
117 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
118 return E_NOINTERFACE;
121 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
123 TRACE("(%p)\n", iface);
124 return 2;
127 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
129 TRACE("(%p)\n", iface);
130 return 1;
133 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
135 TRACE("(%p)->(%x)\n", iface, fLock);
137 if(fLock)
138 lock_module();
139 else
140 unlock_module();
142 return S_OK;
145 static HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
146 REFIID riid, void **ppv)
148 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
150 if(outer) {
151 *ppv = NULL;
152 return CLASS_E_NOAGGREGATION;
155 return create_jscript_object(FALSE, riid, ppv);
158 static const IClassFactoryVtbl JScriptFactoryVtbl = {
159 ClassFactory_QueryInterface,
160 ClassFactory_AddRef,
161 ClassFactory_Release,
162 JScriptFactory_CreateInstance,
163 ClassFactory_LockServer
166 static IClassFactory JScriptFactory = { &JScriptFactoryVtbl };
168 static HRESULT WINAPI JScriptEncodeFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
169 REFIID riid, void **ppv)
171 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
173 if(outer) {
174 *ppv = NULL;
175 return CLASS_E_NOAGGREGATION;
178 return create_jscript_object(TRUE, riid, ppv);
181 static const IClassFactoryVtbl JScriptEncodeFactoryVtbl = {
182 ClassFactory_QueryInterface,
183 ClassFactory_AddRef,
184 ClassFactory_Release,
185 JScriptEncodeFactory_CreateInstance,
186 ClassFactory_LockServer
189 static IClassFactory JScriptEncodeFactory = { &JScriptEncodeFactoryVtbl };
191 /******************************************************************
192 * DllMain (jscript.@)
194 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
196 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpv);
198 switch(fdwReason) {
199 case DLL_PROCESS_ATTACH:
200 DisableThreadLibraryCalls(hInstDLL);
201 jscript_hinstance = hInstDLL;
202 jscript_tls = TlsAlloc();
203 if(jscript_tls == TLS_OUT_OF_INDEXES || !init_strings())
204 return FALSE;
205 break;
206 case DLL_PROCESS_DETACH:
207 if (lpv) break;
208 if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
209 if(jscript_tls != TLS_OUT_OF_INDEXES) TlsFree(jscript_tls);
210 free_strings();
211 break;
214 return TRUE;
217 /***********************************************************************
218 * DllGetClassObject (jscript.@)
220 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
222 if(IsEqualGUID(&CLSID_JScript, rclsid)) {
223 TRACE("(CLSID_JScript %s %p)\n", debugstr_guid(riid), ppv);
224 return IClassFactory_QueryInterface(&JScriptFactory, riid, ppv);
227 if(IsEqualGUID(&CLSID_JScriptEncode, rclsid)) {
228 TRACE("(CLSID_JScriptEncode %s %p)\n", debugstr_guid(riid), ppv);
229 return IClassFactory_QueryInterface(&JScriptEncodeFactory, riid, ppv);
232 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
233 return CLASS_E_CLASSNOTAVAILABLE;
236 /***********************************************************************
237 * DllCanUnloadNow (jscript.@)
239 HRESULT WINAPI DllCanUnloadNow(void)
241 TRACE("() ref=%ld\n", module_ref);
243 return module_ref ? S_FALSE : S_OK;