configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / msi / msi_main.c
blobdf29184ab923b0d1a96999bc2682a3a129327a38
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 INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
45 DWORD gUIFilter = 0;
46 LPVOID gUIContext = NULL;
47 WCHAR gszLogFile[MAX_PATH];
48 HINSTANCE msi_hInstance;
50 static WCHAR msi_path[MAX_PATH];
51 static ITypeLib *msi_typelib;
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 break;
77 case DLL_PROCESS_DETACH:
78 if (msi_typelib) ITypeLib_Release( msi_typelib );
79 msi_dialog_unregister_class();
80 msi_free_handle_table();
81 break;
83 return TRUE;
86 static CRITICAL_SECTION MSI_typelib_cs;
87 static CRITICAL_SECTION_DEBUG MSI_typelib_cs_debug =
89 0, 0, &MSI_typelib_cs,
90 { &MSI_typelib_cs_debug.ProcessLocksList,
91 &MSI_typelib_cs_debug.ProcessLocksList },
92 0, 0, { (DWORD_PTR)(__FILE__ ": MSI_typelib_cs") }
94 static CRITICAL_SECTION MSI_typelib_cs = { &MSI_typelib_cs_debug, -1, 0, 0, 0, 0 };
96 ITypeLib *get_msi_typelib( LPWSTR *path )
98 EnterCriticalSection( &MSI_typelib_cs );
100 if (!msi_typelib)
102 TRACE("loading typelib\n");
104 if (GetModuleFileNameW( msi_hInstance, msi_path, MAX_PATH ))
105 LoadTypeLib( msi_path, &msi_typelib );
108 LeaveCriticalSection( &MSI_typelib_cs );
110 if (path)
111 *path = msi_path;
113 if (msi_typelib)
114 ITypeLib_AddRef( msi_typelib );
116 return msi_typelib;
119 typedef struct tagIClassFactoryImpl {
120 const IClassFactoryVtbl *lpVtbl;
121 HRESULT (*create_object)( IUnknown*, LPVOID* );
122 } IClassFactoryImpl;
124 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
125 REFIID riid,LPVOID *ppobj)
127 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
129 TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);
131 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
132 IsEqualCLSID( riid, &IID_IClassFactory ) )
134 IClassFactory_AddRef( iface );
135 *ppobj = iface;
136 return S_OK;
138 return E_NOINTERFACE;
141 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
143 LockModule();
144 return 2;
147 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
149 UnlockModule();
150 return 1;
153 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
154 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
156 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
157 IUnknown *unk = NULL;
158 HRESULT r;
160 TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
162 r = This->create_object( pOuter, (LPVOID*) &unk );
163 if (SUCCEEDED(r))
165 r = IUnknown_QueryInterface( unk, riid, ppobj );
166 IUnknown_Release( unk );
168 return r;
171 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
173 TRACE("%p %d\n", iface, dolock);
175 if (dolock)
176 LockModule();
177 else
178 UnlockModule();
180 return S_OK;
183 static const IClassFactoryVtbl MsiCF_Vtbl =
185 MsiCF_QueryInterface,
186 MsiCF_AddRef,
187 MsiCF_Release,
188 MsiCF_CreateInstance,
189 MsiCF_LockServer
192 static IClassFactoryImpl MsiServer_CF = { &MsiCF_Vtbl, create_msiserver };
193 static IClassFactoryImpl WineMsiCustomRemote_CF = { &MsiCF_Vtbl, create_msi_custom_remote };
194 static IClassFactoryImpl WineMsiRemotePackage_CF = { &MsiCF_Vtbl, create_msi_remote_package };
196 /******************************************************************
197 * DllGetClassObject [MSI.@]
199 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
201 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
203 if ( IsEqualCLSID (rclsid, &CLSID_IMsiServerX2) )
205 *ppv = &MsiServer_CF;
206 return S_OK;
209 if ( IsEqualCLSID (rclsid, &CLSID_IWineMsiRemoteCustomAction) )
211 *ppv = &WineMsiCustomRemote_CF;
212 return S_OK;
215 if ( IsEqualCLSID (rclsid, &CLSID_IWineMsiRemotePackage) )
217 *ppv = &WineMsiRemotePackage_CF;
218 return S_OK;
221 if( IsEqualCLSID (rclsid, &CLSID_IMsiServerMessage) ||
222 IsEqualCLSID (rclsid, &CLSID_IMsiServer) ||
223 IsEqualCLSID (rclsid, &CLSID_IMsiServerX1) ||
224 IsEqualCLSID (rclsid, &CLSID_IMsiServerX3) )
226 FIXME("create %s object\n", debugstr_guid( rclsid ));
229 return CLASS_E_CLASSNOTAVAILABLE;
232 /******************************************************************
233 * DllGetVersion [MSI.@]
235 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
237 TRACE("%p\n",pdvi);
239 if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
240 return E_INVALIDARG;
242 pdvi->dwMajorVersion = MSI_MAJORVERSION;
243 pdvi->dwMinorVersion = MSI_MINORVERSION;
244 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
245 pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
247 return S_OK;
250 /******************************************************************
251 * DllCanUnloadNow [MSI.@]
253 HRESULT WINAPI DllCanUnloadNow(void)
255 return dll_count == 0 ? S_OK : S_FALSE;