configure: Add a check for sys/ucontext.h and include it where appropriate.
[wine.git] / dlls / msi / msi_main.c
blob148e6787628d511154f81e7c2d71c9e961360727
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2006 Mike McCormack for CodeWeavers
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.
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.
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
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "shlwapi.h"
30 #include "oleauto.h"
31 #include "rpcproxy.h"
32 #include "msipriv.h"
33 #include "msiserver.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msi);
39 static LONG dll_count;
41 /* the UI level */
42 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
43 HWND gUIhwnd = 0;
44 INSTALLUI_HANDLERA gUIHandlerA = NULL;
45 INSTALLUI_HANDLERW gUIHandlerW = NULL;
46 INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
47 DWORD gUIFilter = 0;
48 LPVOID gUIContext = NULL;
49 WCHAR *gszLogFile = NULL;
50 HINSTANCE msi_hInstance;
54 * Dll lifetime tracking declaration
56 static void LockModule(void)
58 InterlockedIncrement(&dll_count);
61 static void UnlockModule(void)
63 InterlockedDecrement(&dll_count);
66 /******************************************************************
67 * DllMain
69 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
71 switch (fdwReason)
73 case DLL_PROCESS_ATTACH:
74 msi_hInstance = hinstDLL;
75 DisableThreadLibraryCalls(hinstDLL);
76 IsWow64Process( GetCurrentProcess(), &is_wow64 );
77 break;
78 case DLL_PROCESS_DETACH:
79 if (lpvReserved) break;
80 msi_dialog_unregister_class();
81 msi_free_handle_table();
82 msi_free( gszLogFile );
83 release_typelib();
84 break;
86 return TRUE;
89 typedef struct tagIClassFactoryImpl {
90 IClassFactory IClassFactory_iface;
91 HRESULT (*create_object)( IUnknown*, LPVOID* );
92 } IClassFactoryImpl;
94 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
96 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
99 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
100 REFIID riid,LPVOID *ppobj)
102 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
104 TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);
106 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
107 IsEqualCLSID( riid, &IID_IClassFactory ) )
109 IClassFactory_AddRef( iface );
110 *ppobj = iface;
111 return S_OK;
113 return E_NOINTERFACE;
116 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
118 LockModule();
119 return 2;
122 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
124 UnlockModule();
125 return 1;
128 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
129 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
131 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
132 IUnknown *unk = NULL;
133 HRESULT r;
135 TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
137 r = This->create_object( pOuter, (LPVOID*) &unk );
138 if (SUCCEEDED(r))
140 r = IUnknown_QueryInterface( unk, riid, ppobj );
141 IUnknown_Release( unk );
143 return r;
146 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
148 TRACE("%p %d\n", iface, dolock);
150 if (dolock)
151 LockModule();
152 else
153 UnlockModule();
155 return S_OK;
158 static const IClassFactoryVtbl MsiCF_Vtbl =
160 MsiCF_QueryInterface,
161 MsiCF_AddRef,
162 MsiCF_Release,
163 MsiCF_CreateInstance,
164 MsiCF_LockServer
167 static IClassFactoryImpl MsiServer_CF = { { &MsiCF_Vtbl }, create_msiserver };
168 static IClassFactoryImpl WineMsiCustomRemote_CF = { { &MsiCF_Vtbl }, create_msi_custom_remote };
169 static IClassFactoryImpl WineMsiRemotePackage_CF = { { &MsiCF_Vtbl }, create_msi_remote_package };
171 /******************************************************************
172 * DllGetClassObject [MSI.@]
174 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
176 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
178 if ( IsEqualCLSID (rclsid, &CLSID_MsiInstaller) )
180 *ppv = &MsiServer_CF;
181 return S_OK;
184 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemoteCustomAction) )
186 *ppv = &WineMsiCustomRemote_CF;
187 return S_OK;
190 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemotePackage) )
192 *ppv = &WineMsiRemotePackage_CF;
193 return S_OK;
196 if( IsEqualCLSID (rclsid, &CLSID_MsiServerMessage) ||
197 IsEqualCLSID (rclsid, &CLSID_MsiServer) ||
198 IsEqualCLSID (rclsid, &CLSID_PSFactoryBuffer) ||
199 IsEqualCLSID (rclsid, &CLSID_MsiServerX3) )
201 FIXME("create %s object\n", debugstr_guid( rclsid ));
204 return CLASS_E_CLASSNOTAVAILABLE;
207 /******************************************************************
208 * DllGetVersion [MSI.@]
210 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
212 TRACE("%p\n",pdvi);
214 if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
215 return E_INVALIDARG;
217 pdvi->dwMajorVersion = MSI_MAJORVERSION;
218 pdvi->dwMinorVersion = MSI_MINORVERSION;
219 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
220 pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
222 return S_OK;
225 /******************************************************************
226 * DllCanUnloadNow [MSI.@]
228 HRESULT WINAPI DllCanUnloadNow(void)
230 return dll_count == 0 ? S_OK : S_FALSE;
233 /***********************************************************************
234 * DllRegisterServer (MSI.@)
236 HRESULT WINAPI DllRegisterServer(void)
238 return __wine_register_resources( msi_hInstance );
241 /***********************************************************************
242 * DllUnregisterServer (MSI.@)
244 HRESULT WINAPI DllUnregisterServer(void)
246 return __wine_unregister_resources( msi_hInstance );