jscript: Added Dll[Un]RegisterServer 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 "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "ole2.h"
31 #include "advpub.h"
32
33 #include "initguid.h"
34 #include "activscp.h"
35 #include "activaut.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
40
41 static const CLSID CLSID_JScript =
42     {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
43 static const CLSID CLSID_JScriptAuthor =
44     {0xf414c261,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
45 static const CLSID CLSID_JScriptEncode =
46     {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
47
48 static HINSTANCE jscript_hinstance;
49
50 /******************************************************************
51  *              DllMain (jscript.@)
52  */
53 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
54 {
55     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
56
57     switch(fdwReason)
58     {
59     case DLL_WINE_PREATTACH:
60         return FALSE;  /* prefer native version */
61     case DLL_PROCESS_ATTACH:
62         DisableThreadLibraryCalls(hInstDLL);
63         jscript_hinstance = hInstDLL;
64         break;
65     }
66
67     return TRUE;
68 }
69
70 /***********************************************************************
71  *              DllGetClassObject       (jscript.@)
72  */
73 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
74 {
75     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
76     return CLASS_E_CLASSNOTAVAILABLE;
77 }
78
79 /***********************************************************************
80  *          DllCanUnloadNow (jscript.@)
81  */
82 HRESULT WINAPI DllCanUnloadNow(void)
83 {
84     FIXME("()\n");
85     return S_FALSE;
86 }
87
88 /***********************************************************************
89  *              register_inf
90  */
91
92 #define INF_SET_ID(id)             \
93     do                             \
94     {                              \
95         static CHAR name[] = #id;  \
96                                    \
97         pse[i].pszName = name;     \
98         clsids[i++] = &id;         \
99     } while (0)
100
101 static HRESULT register_inf(BOOL doregister)
102 {
103     HRESULT hres;
104     HMODULE hAdvpack;
105     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
106     STRTABLEA strtable;
107     STRENTRYA pse[7];
108     static CLSID const *clsids[7];
109     int i = 0;
110
111     static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
112
113     INF_SET_ID(CLSID_JScript);
114     INF_SET_ID(CLSID_JScriptAuthor);
115     INF_SET_ID(CLSID_JScriptEncode);
116     INF_SET_ID(CATID_ActiveScript);
117     INF_SET_ID(CATID_ActiveScriptParse);
118     INF_SET_ID(CATID_ActiveScriptEncode);
119     INF_SET_ID(CATID_ActiveScriptAuthor);
120
121     for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
122         pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
123         sprintf(pse[i].pszValue, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
124                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
125                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
126                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
127     }
128
129     strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
130     strtable.pse = pse;
131
132     hAdvpack = LoadLibraryW(advpackW);
133     pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
134
135     hres = pRegInstall(jscript_hinstance, doregister ? "RegisterDll" : "UnregisterDll", &strtable);
136
137     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
138         HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
139
140     return hres;
141 }
142
143 #undef INF_SET_CLSID
144
145 /***********************************************************************
146  *          DllRegisterServer (jscript.@)
147  */
148 HRESULT WINAPI DllRegisterServer(void)
149 {
150     TRACE("()\n");
151     return register_inf(TRUE);
152 }
153
154 /***********************************************************************
155  *          DllUnregisterServer (jscript.@)
156  */
157 HRESULT WINAPI DllUnregisterServer(void)
158 {
159     TRACE("()\n");
160     return register_inf(FALSE);
161 }