0bf992189c46d8d9abb57fb827f755920ef5974a
[reactos.git] / dll / win32 / msi / msi_main.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "msipriv.h"
22
23 #include <rpcproxy.h>
24
25 WINE_DEFAULT_DEBUG_CHANNEL(msi);
26
27 static LONG dll_count;
28
29 /* the UI level */
30 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
31 HWND gUIhwnd = 0;
32 INSTALLUI_HANDLERA gUIHandlerA = NULL;
33 INSTALLUI_HANDLERW gUIHandlerW = NULL;
34 INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
35 DWORD gUIFilter = 0;
36 LPVOID gUIContext = NULL;
37 WCHAR *gszLogFile = NULL;
38 HINSTANCE msi_hInstance;
39
40
41 /*
42 * Dll lifetime tracking declaration
43 */
44 static void LockModule(void)
45 {
46 InterlockedIncrement(&dll_count);
47 }
48
49 static void UnlockModule(void)
50 {
51 InterlockedDecrement(&dll_count);
52 }
53
54 /******************************************************************
55 * DllMain
56 */
57 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
58 {
59 switch (fdwReason)
60 {
61 case DLL_PROCESS_ATTACH:
62 msi_hInstance = hinstDLL;
63 DisableThreadLibraryCalls(hinstDLL);
64 IsWow64Process( GetCurrentProcess(), &is_wow64 );
65 break;
66 case DLL_PROCESS_DETACH:
67 if (lpvReserved) break;
68 msi_dialog_unregister_class();
69 msi_free_handle_table();
70 msi_free( gszLogFile );
71 release_typelib();
72 break;
73 }
74 return TRUE;
75 }
76
77 typedef struct tagIClassFactoryImpl {
78 IClassFactory IClassFactory_iface;
79 HRESULT (*create_object)( IUnknown*, LPVOID* );
80 } IClassFactoryImpl;
81
82 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
83 {
84 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
85 }
86
87 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
88 REFIID riid,LPVOID *ppobj)
89 {
90 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
91
92 TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);
93
94 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
95 IsEqualCLSID( riid, &IID_IClassFactory ) )
96 {
97 IClassFactory_AddRef( iface );
98 *ppobj = iface;
99 return S_OK;
100 }
101 return E_NOINTERFACE;
102 }
103
104 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
105 {
106 LockModule();
107 return 2;
108 }
109
110 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
111 {
112 UnlockModule();
113 return 1;
114 }
115
116 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
117 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
118 {
119 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
120 IUnknown *unk = NULL;
121 HRESULT r;
122
123 TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
124
125 r = This->create_object( pOuter, (LPVOID*) &unk );
126 if (SUCCEEDED(r))
127 {
128 r = IUnknown_QueryInterface( unk, riid, ppobj );
129 IUnknown_Release( unk );
130 }
131 return r;
132 }
133
134 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
135 {
136 TRACE("%p %d\n", iface, dolock);
137
138 if (dolock)
139 LockModule();
140 else
141 UnlockModule();
142
143 return S_OK;
144 }
145
146 static const IClassFactoryVtbl MsiCF_Vtbl =
147 {
148 MsiCF_QueryInterface,
149 MsiCF_AddRef,
150 MsiCF_Release,
151 MsiCF_CreateInstance,
152 MsiCF_LockServer
153 };
154
155 static IClassFactoryImpl MsiServer_CF = { { &MsiCF_Vtbl }, create_msiserver };
156 static IClassFactoryImpl WineMsiCustomRemote_CF = { { &MsiCF_Vtbl }, create_msi_custom_remote };
157 static IClassFactoryImpl WineMsiRemotePackage_CF = { { &MsiCF_Vtbl }, create_msi_remote_package };
158
159 /******************************************************************
160 * DllGetClassObject [MSI.@]
161 */
162 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
163 {
164 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
165
166 if ( IsEqualCLSID (rclsid, &CLSID_MsiInstaller) )
167 {
168 *ppv = &MsiServer_CF;
169 return S_OK;
170 }
171
172 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemoteCustomAction) )
173 {
174 *ppv = &WineMsiCustomRemote_CF;
175 return S_OK;
176 }
177
178 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemotePackage) )
179 {
180 *ppv = &WineMsiRemotePackage_CF;
181 return S_OK;
182 }
183
184 if( IsEqualCLSID (rclsid, &CLSID_MsiServerMessage) ||
185 IsEqualCLSID (rclsid, &CLSID_MsiServer) ||
186 IsEqualCLSID (rclsid, &CLSID_PSFactoryBuffer) ||
187 IsEqualCLSID (rclsid, &CLSID_MsiServerX3) )
188 {
189 FIXME("create %s object\n", debugstr_guid( rclsid ));
190 }
191
192 return CLASS_E_CLASSNOTAVAILABLE;
193 }
194
195 /******************************************************************
196 * DllGetVersion [MSI.@]
197 */
198 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
199 {
200 TRACE("%p\n",pdvi);
201
202 if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
203 return E_INVALIDARG;
204
205 pdvi->dwMajorVersion = MSI_MAJORVERSION;
206 pdvi->dwMinorVersion = MSI_MINORVERSION;
207 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
208 pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
209
210 return S_OK;
211 }
212
213 /******************************************************************
214 * DllCanUnloadNow [MSI.@]
215 */
216 HRESULT WINAPI DllCanUnloadNow(void)
217 {
218 return dll_count == 0 ? S_OK : S_FALSE;
219 }
220
221 /***********************************************************************
222 * DllRegisterServer (MSI.@)
223 */
224 HRESULT WINAPI DllRegisterServer(void)
225 {
226 return __wine_register_resources( msi_hInstance );
227 }
228
229 /***********************************************************************
230 * DllUnregisterServer (MSI.@)
231 */
232 HRESULT WINAPI DllUnregisterServer(void)
233 {
234 return __wine_unregister_resources( msi_hInstance );
235 }