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