- sync MSI to Wine 0.9.18
[reactos.git] / reactos / 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 <stdarg.h>
22
23 #define COBJMACROS
24 #define NONAMELESSUNION
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "shlwapi.h"
30 #include "msipriv.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(msi);
35
36 static LONG dll_count;
37
38 /* the UI level */
39 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
40 HWND gUIhwnd = 0;
41 INSTALLUI_HANDLERA gUIHandlerA = NULL;
42 INSTALLUI_HANDLERW gUIHandlerW = NULL;
43 DWORD gUIFilter = 0;
44 LPVOID gUIContext = NULL;
45 WCHAR gszLogFile[MAX_PATH];
46 HINSTANCE msi_hInstance;
47
48 /*
49 * Dll lifetime tracking declaration
50 */
51 static void LockModule(void)
52 {
53 InterlockedIncrement(&dll_count);
54 }
55
56 static void UnlockModule(void)
57 {
58 InterlockedDecrement(&dll_count);
59 }
60
61 /******************************************************************
62 * DllMain
63 */
64 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
65 {
66 switch (fdwReason)
67 {
68 case DLL_PROCESS_ATTACH:
69 msi_hInstance = hinstDLL;
70 DisableThreadLibraryCalls(hinstDLL);
71 msi_dialog_register_class();
72 break;
73 case DLL_PROCESS_DETACH:
74 msi_dialog_unregister_class();
75 break;
76 }
77 return TRUE;
78 }
79
80 typedef struct tagIClassFactoryImpl
81 {
82 const IClassFactoryVtbl *lpVtbl;
83 } IClassFactoryImpl;
84
85 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
86 REFIID riid,LPVOID *ppobj)
87 {
88 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
89 FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
90 return E_NOINTERFACE;
91 }
92
93 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
94 {
95 LockModule();
96 return 2;
97 }
98
99 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
100 {
101 UnlockModule();
102 return 1;
103 }
104
105 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
106 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
107 {
108 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
109
110 FIXME("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
111 return E_FAIL;
112 }
113
114 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
115 {
116 TRACE("%p %d\n", iface, dolock);
117
118 if (dolock)
119 LockModule();
120 else
121 UnlockModule();
122
123 return S_OK;
124 }
125
126 static const IClassFactoryVtbl MsiCF_Vtbl =
127 {
128 MsiCF_QueryInterface,
129 MsiCF_AddRef,
130 MsiCF_Release,
131 MsiCF_CreateInstance,
132 MsiCF_LockServer
133 };
134
135 static IClassFactoryImpl Msi_CF = { &MsiCF_Vtbl };
136
137 /******************************************************************
138 * DllGetClassObject [MSI.@]
139 */
140 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
141 {
142 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
143
144 if( IsEqualCLSID (rclsid, &CLSID_IMsiServer) ||
145 IsEqualCLSID (rclsid, &CLSID_IMsiServerMessage) ||
146 IsEqualCLSID (rclsid, &CLSID_IMsiServerX1) ||
147 IsEqualCLSID (rclsid, &CLSID_IMsiServerX2) ||
148 IsEqualCLSID (rclsid, &CLSID_IMsiServerX3) )
149 {
150 *ppv = (LPVOID) &Msi_CF;
151 return S_OK;
152 }
153 return CLASS_E_CLASSNOTAVAILABLE;
154 }
155
156 /******************************************************************
157 * DllGetVersion [MSI.@]
158 */
159 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
160 {
161 TRACE("%p\n",pdvi);
162
163 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
164 return E_INVALIDARG;
165
166 pdvi->dwMajorVersion = MSI_MAJORVERSION;
167 pdvi->dwMinorVersion = MSI_MINORVERSION;
168 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
169 pdvi->dwPlatformID = 1;
170
171 return S_OK;
172 }
173
174 /******************************************************************
175 * DllCanUnloadNow [MSI.@]
176 */
177 HRESULT WINAPI DllCanUnloadNow(void)
178 {
179 return dll_count == 0 ? S_OK : S_FALSE;
180 }