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