jscript: Return DateInstance from create_date.
[wine/zf.git] / dlls / jscript / jscript_main.c
blob532cdf96d94e12b79c5191e701c740c5b49cc195
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 ITypeInfo *dispatch_typeinfo;
42 HRESULT get_dispatch_typeinfo(ITypeInfo **out)
44 ITypeInfo *typeinfo;
45 ITypeLib *typelib;
46 HRESULT hr;
48 if (!dispatch_typeinfo)
50 hr = LoadRegTypeLib(&IID_StdOle, STDOLE_MAJORVERNUM, STDOLE_MINORVERNUM, STDOLE_LCID, &typelib);
51 if (FAILED(hr)) return hr;
53 hr = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IDispatch, &typeinfo);
54 ITypeLib_Release(typelib);
55 if (FAILED(hr)) return hr;
57 if (InterlockedCompareExchangePointer((void**)&dispatch_typeinfo, typeinfo, NULL))
58 ITypeInfo_Release(typeinfo);
61 *out = dispatch_typeinfo;
62 return S_OK;
65 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
67 *ppv = NULL;
69 if(IsEqualGUID(&IID_IUnknown, riid)) {
70 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
71 *ppv = iface;
72 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
73 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
74 *ppv = iface;
77 if(*ppv) {
78 IUnknown_AddRef((IUnknown*)*ppv);
79 return S_OK;
82 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
83 return E_NOINTERFACE;
86 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
88 TRACE("(%p)\n", iface);
89 return 2;
92 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
94 TRACE("(%p)\n", iface);
95 return 1;
98 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
100 TRACE("(%p)->(%x)\n", iface, fLock);
102 if(fLock)
103 lock_module();
104 else
105 unlock_module();
107 return S_OK;
110 static HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
111 REFIID riid, void **ppv)
113 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
115 if(outer) {
116 *ppv = NULL;
117 return CLASS_E_NOAGGREGATION;
120 return create_jscript_object(FALSE, riid, ppv);
123 static const IClassFactoryVtbl JScriptFactoryVtbl = {
124 ClassFactory_QueryInterface,
125 ClassFactory_AddRef,
126 ClassFactory_Release,
127 JScriptFactory_CreateInstance,
128 ClassFactory_LockServer
131 static IClassFactory JScriptFactory = { &JScriptFactoryVtbl };
133 static HRESULT WINAPI JScriptEncodeFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
134 REFIID riid, void **ppv)
136 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
138 if(outer) {
139 *ppv = NULL;
140 return CLASS_E_NOAGGREGATION;
143 return create_jscript_object(TRUE, riid, ppv);
146 static const IClassFactoryVtbl JScriptEncodeFactoryVtbl = {
147 ClassFactory_QueryInterface,
148 ClassFactory_AddRef,
149 ClassFactory_Release,
150 JScriptEncodeFactory_CreateInstance,
151 ClassFactory_LockServer
154 static IClassFactory JScriptEncodeFactory = { &JScriptEncodeFactoryVtbl };
156 /******************************************************************
157 * DllMain (jscript.@)
159 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
161 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
163 switch(fdwReason) {
164 case DLL_PROCESS_ATTACH:
165 DisableThreadLibraryCalls(hInstDLL);
166 jscript_hinstance = hInstDLL;
167 if(!init_strings())
168 return FALSE;
169 break;
170 case DLL_PROCESS_DETACH:
171 if (lpv) break;
172 if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
173 free_strings();
176 return TRUE;
179 /***********************************************************************
180 * DllGetClassObject (jscript.@)
182 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
184 if(IsEqualGUID(&CLSID_JScript, rclsid)) {
185 TRACE("(CLSID_JScript %s %p)\n", debugstr_guid(riid), ppv);
186 return IClassFactory_QueryInterface(&JScriptFactory, riid, ppv);
189 if(IsEqualGUID(&CLSID_JScriptEncode, rclsid)) {
190 TRACE("(CLSID_JScriptEncode %s %p)\n", debugstr_guid(riid), ppv);
191 return IClassFactory_QueryInterface(&JScriptEncodeFactory, riid, ppv);
194 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
195 return CLASS_E_CLASSNOTAVAILABLE;
198 /***********************************************************************
199 * DllCanUnloadNow (jscript.@)
201 HRESULT WINAPI DllCanUnloadNow(void)
203 TRACE("() ref=%d\n", module_ref);
205 return module_ref ? S_FALSE : S_OK;
208 /***********************************************************************
209 * DllRegisterServer (jscript.@)
211 HRESULT WINAPI DllRegisterServer(void)
213 TRACE("()\n");
214 return __wine_register_resources(jscript_hinstance);
217 /***********************************************************************
218 * DllUnregisterServer (jscript.@)
220 HRESULT WINAPI DllUnregisterServer(void)
222 TRACE("()\n");
223 return __wine_unregister_resources(jscript_hinstance);