msi: Don't flag an error in the InstallServices action if the component does not...
[wine] / dlls / 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 "initguid.h"
20
21 #include "jscript.h"
22
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"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
34
35 LONG module_ref = 0;
36
37 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
38
39 HINSTANCE jscript_hinstance;
40
41 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
42 {
43     *ppv = NULL;
44
45     if(IsEqualGUID(&IID_IUnknown, riid)) {
46         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
47         *ppv = iface;
48     }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
49         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
50         *ppv = iface;
51     }
52
53     if(*ppv) {
54         IUnknown_AddRef((IUnknown*)*ppv);
55         return S_OK;
56     }
57
58     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
59     return E_NOINTERFACE;
60 }
61
62 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
63 {
64     TRACE("(%p)\n", iface);
65     return 2;
66 }
67
68 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
69 {
70     TRACE("(%p)\n", iface);
71     return 1;
72 }
73
74 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
75 {
76     TRACE("(%p)->(%x)\n", iface, fLock);
77
78     if(fLock)
79         lock_module();
80     else
81         unlock_module();
82
83     return S_OK;
84 }
85
86 static const IClassFactoryVtbl JScriptFactoryVtbl = {
87     ClassFactory_QueryInterface,
88     ClassFactory_AddRef,
89     ClassFactory_Release,
90     JScriptFactory_CreateInstance,
91     ClassFactory_LockServer
92 };
93
94 static IClassFactory JScriptFactory = { &JScriptFactoryVtbl };
95
96 /******************************************************************
97  *              DllMain (jscript.@)
98  */
99 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
100 {
101     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
102
103     switch(fdwReason)
104     {
105     case DLL_WINE_PREATTACH:
106         return FALSE;  /* prefer native version */
107     case DLL_PROCESS_ATTACH:
108         DisableThreadLibraryCalls(hInstDLL);
109         jscript_hinstance = hInstDLL;
110         break;
111     }
112
113     return TRUE;
114 }
115
116 /***********************************************************************
117  *              DllGetClassObject       (jscript.@)
118  */
119 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
120 {
121     if(IsEqualGUID(&CLSID_JScript, rclsid)) {
122         TRACE("(CLSID_JScript %s %p)\n", debugstr_guid(riid), ppv);
123         return IClassFactory_QueryInterface(&JScriptFactory, riid, ppv);
124     }
125
126     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
127     return CLASS_E_CLASSNOTAVAILABLE;
128 }
129
130 /***********************************************************************
131  *          DllCanUnloadNow (jscript.@)
132  */
133 HRESULT WINAPI DllCanUnloadNow(void)
134 {
135     TRACE("() ref=%d\n", module_ref);
136
137     return module_ref ? S_FALSE : S_OK;
138 }
139
140 /***********************************************************************
141  *              register_inf
142  */
143
144 #define INF_SET_ID(id)             \
145     do                             \
146     {                              \
147         static CHAR name[] = #id;  \
148                                    \
149         pse[i].pszName = name;     \
150         clsids[i++] = &id;         \
151     } while (0)
152
153 static HRESULT register_inf(BOOL doregister)
154 {
155     HRESULT hres;
156     HMODULE hAdvpack;
157     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
158     STRTABLEA strtable;
159     STRENTRYA pse[7];
160     static CLSID const *clsids[7];
161     unsigned int i = 0;
162
163     static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
164
165     INF_SET_ID(CLSID_JScript);
166     INF_SET_ID(CLSID_JScriptAuthor);
167     INF_SET_ID(CLSID_JScriptEncode);
168     INF_SET_ID(CATID_ActiveScript);
169     INF_SET_ID(CATID_ActiveScriptParse);
170     INF_SET_ID(CATID_ActiveScriptEncode);
171     INF_SET_ID(CATID_ActiveScriptAuthor);
172
173     for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
174         pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
175         sprintf(pse[i].pszValue, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
176                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
177                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
178                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
179     }
180
181     strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
182     strtable.pse = pse;
183
184     hAdvpack = LoadLibraryW(advpackW);
185     pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
186
187     hres = pRegInstall(jscript_hinstance, doregister ? "RegisterDll" : "UnregisterDll", &strtable);
188
189     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
190         HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
191
192     return hres;
193 }
194
195 #undef INF_SET_CLSID
196
197 /***********************************************************************
198  *          DllRegisterServer (jscript.@)
199  */
200 HRESULT WINAPI DllRegisterServer(void)
201 {
202     HRESULT hres;
203
204     TRACE("()\n");
205
206     hres = __wine_register_resources(jscript_hinstance, NULL);
207     if(FAILED(hres))
208        return hres;
209
210     return register_inf(TRUE);
211 }
212
213 /***********************************************************************
214  *          DllUnregisterServer (jscript.@)
215  */
216 HRESULT WINAPI DllUnregisterServer(void)
217 {
218     HRESULT hres;
219
220     TRACE("()\n");
221
222     hres = __wine_unregister_resources(jscript_hinstance, NULL);
223     if(FAILED(hres))
224         return hres;
225
226     return register_inf(FALSE);
227 }