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