[JSCRIPT]
[reactos.git] / reactos / dll / win32 / jscript / jscript_main.c
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "jscript.h"
20
21 #include <initguid.h>
22 #include <rpcproxy.h>
23 #include <jscript_classes.h>
24
25 LONG module_ref = 0;
26
27 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
28
29 HINSTANCE jscript_hinstance;
30
31 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
32 {
33 *ppv = NULL;
34
35 if(IsEqualGUID(&IID_IUnknown, riid)) {
36 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
37 *ppv = iface;
38 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
39 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
40 *ppv = iface;
41 }
42
43 if(*ppv) {
44 IUnknown_AddRef((IUnknown*)*ppv);
45 return S_OK;
46 }
47
48 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
49 return E_NOINTERFACE;
50 }
51
52 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
53 {
54 TRACE("(%p)\n", iface);
55 return 2;
56 }
57
58 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
59 {
60 TRACE("(%p)\n", iface);
61 return 1;
62 }
63
64 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
65 {
66 TRACE("(%p)->(%x)\n", iface, fLock);
67
68 if(fLock)
69 lock_module();
70 else
71 unlock_module();
72
73 return S_OK;
74 }
75
76 static HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
77 REFIID riid, void **ppv)
78 {
79 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
80
81 if(outer) {
82 *ppv = NULL;
83 return CLASS_E_NOAGGREGATION;
84 }
85
86 return create_jscript_object(FALSE, riid, ppv);
87 }
88
89 static const IClassFactoryVtbl JScriptFactoryVtbl = {
90 ClassFactory_QueryInterface,
91 ClassFactory_AddRef,
92 ClassFactory_Release,
93 JScriptFactory_CreateInstance,
94 ClassFactory_LockServer
95 };
96
97 static IClassFactory JScriptFactory = { &JScriptFactoryVtbl };
98
99 static HRESULT WINAPI JScriptEncodeFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
100 REFIID riid, void **ppv)
101 {
102 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
103
104 if(outer) {
105 *ppv = NULL;
106 return CLASS_E_NOAGGREGATION;
107 }
108
109 return create_jscript_object(TRUE, riid, ppv);
110 }
111
112 static const IClassFactoryVtbl JScriptEncodeFactoryVtbl = {
113 ClassFactory_QueryInterface,
114 ClassFactory_AddRef,
115 ClassFactory_Release,
116 JScriptEncodeFactory_CreateInstance,
117 ClassFactory_LockServer
118 };
119
120 static IClassFactory JScriptEncodeFactory = { &JScriptEncodeFactoryVtbl };
121
122 /******************************************************************
123 * DllMain (jscript.@)
124 */
125 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
126 {
127 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
128
129 switch(fdwReason) {
130 case DLL_PROCESS_ATTACH:
131 DisableThreadLibraryCalls(hInstDLL);
132 jscript_hinstance = hInstDLL;
133 if(!init_strings())
134 return FALSE;
135 break;
136 case DLL_PROCESS_DETACH:
137 if (lpv) break;
138 free_strings();
139 }
140
141 return TRUE;
142 }
143
144 /***********************************************************************
145 * DllGetClassObject (jscript.@)
146 */
147 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
148 {
149 if(IsEqualGUID(&CLSID_JScript, rclsid)) {
150 TRACE("(CLSID_JScript %s %p)\n", debugstr_guid(riid), ppv);
151 return IClassFactory_QueryInterface(&JScriptFactory, riid, ppv);
152 }
153
154 if(IsEqualGUID(&CLSID_JScriptEncode, rclsid)) {
155 TRACE("(CLSID_JScriptEncode %s %p)\n", debugstr_guid(riid), ppv);
156 return IClassFactory_QueryInterface(&JScriptEncodeFactory, riid, ppv);
157 }
158
159 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
160 return CLASS_E_CLASSNOTAVAILABLE;
161 }
162
163 /***********************************************************************
164 * DllCanUnloadNow (jscript.@)
165 */
166 HRESULT WINAPI DllCanUnloadNow(void)
167 {
168 TRACE("() ref=%d\n", module_ref);
169
170 return module_ref ? S_FALSE : S_OK;
171 }
172
173 /***********************************************************************
174 * DllRegisterServer (jscript.@)
175 */
176 HRESULT WINAPI DllRegisterServer(void)
177 {
178 TRACE("()\n");
179 return __wine_register_resources(jscript_hinstance);
180 }
181
182 /***********************************************************************
183 * DllUnregisterServer (jscript.@)
184 */
185 HRESULT WINAPI DllUnregisterServer(void)
186 {
187 TRACE("()\n");
188 return __wine_unregister_resources(jscript_hinstance);
189 }