Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / msi / msi_main.c
blob97f17948f859a8d029e3a7d499f4ecc6d7e947fd
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 "msipriv.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msi);
37 static LONG dll_count;
39 /* the UI level */
40 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
41 HWND gUIhwnd = 0;
42 INSTALLUI_HANDLERA gUIHandlerA = NULL;
43 INSTALLUI_HANDLERW gUIHandlerW = NULL;
44 DWORD gUIFilter = 0;
45 LPVOID gUIContext = NULL;
46 WCHAR gszLogFile[MAX_PATH];
47 WCHAR msi_path[MAX_PATH];
48 ITypeLib *msi_typelib = NULL;
49 HINSTANCE msi_hInstance;
50 DWORD tls_slot;
53 * Dll lifetime tracking declaration
55 static void LockModule(void)
57 InterlockedIncrement(&dll_count);
60 static void UnlockModule(void)
62 InterlockedDecrement(&dll_count);
65 /******************************************************************
66 * DllMain
68 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
70 switch (fdwReason)
72 case DLL_PROCESS_ATTACH:
73 msi_hInstance = hinstDLL;
74 tls_slot = TlsAlloc();
75 DisableThreadLibraryCalls(hinstDLL);
76 msi_dialog_register_class();
77 break;
78 case DLL_PROCESS_DETACH:
79 if (msi_typelib) ITypeLib_Release( msi_typelib );
80 msi_dialog_unregister_class();
81 msi_free_handle_table();
82 break;
84 return TRUE;
87 static CRITICAL_SECTION MSI_typelib_cs;
88 static CRITICAL_SECTION_DEBUG MSI_typelib_cs_debug =
90 0, 0, &MSI_typelib_cs,
91 { &MSI_typelib_cs_debug.ProcessLocksList,
92 &MSI_typelib_cs_debug.ProcessLocksList },
93 0, 0, { (DWORD_PTR)(__FILE__ ": MSI_typelib_cs") }
95 static CRITICAL_SECTION MSI_typelib_cs = { &MSI_typelib_cs_debug, -1, 0, 0, 0, 0 };
97 ITypeLib *get_msi_typelib( LPWSTR *path )
99 EnterCriticalSection( &MSI_typelib_cs );
101 if (!msi_typelib)
103 TRACE("loading typelib\n");
105 if (GetModuleFileNameW( msi_hInstance, msi_path, MAX_PATH ))
106 LoadTypeLib( msi_path, &msi_typelib );
109 LeaveCriticalSection( &MSI_typelib_cs );
111 if (path)
112 *path = msi_path;
114 if (msi_typelib)
115 ITypeLib_AddRef( msi_typelib );
117 return msi_typelib;
120 static HRESULT create_msiserver( IUnknown *pOuter, LPVOID *ppObj )
122 FIXME("\n");
123 return E_FAIL;
126 typedef struct tagIClassFactoryImpl {
127 const IClassFactoryVtbl *lpVtbl;
128 HRESULT (*create_object)( IUnknown*, LPVOID* );
129 } IClassFactoryImpl;
131 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
132 REFIID riid,LPVOID *ppobj)
134 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
136 TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);
138 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
139 IsEqualCLSID( riid, &IID_IClassFactory ) )
141 IClassFactory_AddRef( iface );
142 *ppobj = iface;
143 return S_OK;
145 return E_NOINTERFACE;
148 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
150 LockModule();
151 return 2;
154 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
156 UnlockModule();
157 return 1;
160 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
161 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
163 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
164 IUnknown *unk = NULL;
165 HRESULT r;
167 TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
169 r = This->create_object( pOuter, (LPVOID*) &unk );
170 if (SUCCEEDED(r))
172 r = IUnknown_QueryInterface( unk, riid, ppobj );
173 IUnknown_Release( unk );
175 return r;
178 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
180 TRACE("%p %d\n", iface, dolock);
182 if (dolock)
183 LockModule();
184 else
185 UnlockModule();
187 return S_OK;
190 static const IClassFactoryVtbl MsiCF_Vtbl =
192 MsiCF_QueryInterface,
193 MsiCF_AddRef,
194 MsiCF_Release,
195 MsiCF_CreateInstance,
196 MsiCF_LockServer
199 static IClassFactoryImpl MsiServer_CF = { &MsiCF_Vtbl, create_msiserver };
201 /******************************************************************
202 * DllGetClassObject [MSI.@]
204 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
206 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
208 if ( IsEqualCLSID (rclsid, &CLSID_IMsiServerX2) )
210 *ppv = (LPVOID) &MsiServer_CF;
211 return S_OK;
214 if( IsEqualCLSID (rclsid, &CLSID_IMsiServerMessage) ||
215 IsEqualCLSID (rclsid, &CLSID_IMsiServer) ||
216 IsEqualCLSID (rclsid, &CLSID_IMsiServerX1) ||
217 IsEqualCLSID (rclsid, &CLSID_IMsiServerX3) )
219 FIXME("create %s object\n", debugstr_guid( rclsid ));
222 return CLASS_E_CLASSNOTAVAILABLE;
225 /******************************************************************
226 * DllGetVersion [MSI.@]
228 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
230 TRACE("%p\n",pdvi);
232 if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
233 return E_INVALIDARG;
235 pdvi->dwMajorVersion = MSI_MAJORVERSION;
236 pdvi->dwMinorVersion = MSI_MINORVERSION;
237 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
238 pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
240 return S_OK;
243 /******************************************************************
244 * DllCanUnloadNow [MSI.@]
246 HRESULT WINAPI DllCanUnloadNow(void)
248 return dll_count == 0 ? S_OK : S_FALSE;