services: Check for services without lpBinaryPathName in get_winedevice_process.
[wine.git] / dlls / msi / msi_main.c
blob09558567e8482ef0f02da65375cbd30faeaa5a4f
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
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "oleauto.h"
30 #include "rpcproxy.h"
31 #include "msipriv.h"
32 #include "msiserver.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38 static LONG dll_count;
40 /* the UI level */
41 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
42 HWND gUIhwnd = 0;
43 INSTALLUI_HANDLERA gUIHandlerA = NULL;
44 INSTALLUI_HANDLERW gUIHandlerW = NULL;
45 INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
46 DWORD gUIFilter = 0;
47 LPVOID gUIContext = NULL;
48 WCHAR *gszLogFile = NULL;
49 HINSTANCE msi_hInstance;
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 DisableThreadLibraryCalls(hinstDLL);
75 IsWow64Process( GetCurrentProcess(), &is_wow64 );
76 break;
77 case DLL_PROCESS_DETACH:
78 if (lpvReserved) break;
79 msi_dialog_unregister_class();
80 msi_free_handle_table();
81 msi_free( gszLogFile );
82 release_typelib();
83 break;
85 return TRUE;
88 typedef struct tagIClassFactoryImpl {
89 IClassFactory IClassFactory_iface;
90 HRESULT (*create_object)( IUnknown*, LPVOID* );
91 } IClassFactoryImpl;
93 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
95 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
98 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
99 REFIID riid,LPVOID *ppobj)
101 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
103 TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);
105 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
106 IsEqualCLSID( riid, &IID_IClassFactory ) )
108 IClassFactory_AddRef( iface );
109 *ppobj = iface;
110 return S_OK;
112 return E_NOINTERFACE;
115 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
117 LockModule();
118 return 2;
121 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
123 UnlockModule();
124 return 1;
127 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
128 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
130 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
131 IUnknown *unk = NULL;
132 HRESULT r;
134 TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
136 r = This->create_object( pOuter, (LPVOID*) &unk );
137 if (SUCCEEDED(r))
139 r = IUnknown_QueryInterface( unk, riid, ppobj );
140 IUnknown_Release( unk );
142 return r;
145 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
147 TRACE("%p %d\n", iface, dolock);
149 if (dolock)
150 LockModule();
151 else
152 UnlockModule();
154 return S_OK;
157 static const IClassFactoryVtbl MsiCF_Vtbl =
159 MsiCF_QueryInterface,
160 MsiCF_AddRef,
161 MsiCF_Release,
162 MsiCF_CreateInstance,
163 MsiCF_LockServer
166 static IClassFactoryImpl MsiServer_CF = { { &MsiCF_Vtbl }, create_msiserver };
167 static IClassFactoryImpl WineMsiCustomRemote_CF = { { &MsiCF_Vtbl }, create_msi_custom_remote };
168 static IClassFactoryImpl WineMsiRemotePackage_CF = { { &MsiCF_Vtbl }, create_msi_remote_package };
170 /******************************************************************
171 * DllGetClassObject [MSI.@]
173 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
175 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
177 if ( IsEqualCLSID (rclsid, &CLSID_MsiInstaller) )
179 *ppv = &MsiServer_CF;
180 return S_OK;
183 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemoteCustomAction) )
185 *ppv = &WineMsiCustomRemote_CF;
186 return S_OK;
189 if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemotePackage) )
191 *ppv = &WineMsiRemotePackage_CF;
192 return S_OK;
195 if( IsEqualCLSID (rclsid, &CLSID_MsiServerMessage) ||
196 IsEqualCLSID (rclsid, &CLSID_MsiServer) ||
197 IsEqualCLSID (rclsid, &CLSID_PSFactoryBuffer) ||
198 IsEqualCLSID (rclsid, &CLSID_MsiServerX3) )
200 FIXME("create %s object\n", debugstr_guid( rclsid ));
203 return CLASS_E_CLASSNOTAVAILABLE;
206 /******************************************************************
207 * DllGetVersion [MSI.@]
209 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
211 TRACE("%p\n",pdvi);
213 if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
214 return E_INVALIDARG;
216 pdvi->dwMajorVersion = MSI_MAJORVERSION;
217 pdvi->dwMinorVersion = MSI_MINORVERSION;
218 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
219 pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
221 return S_OK;
224 /******************************************************************
225 * DllCanUnloadNow [MSI.@]
227 HRESULT WINAPI DllCanUnloadNow(void)
229 return dll_count == 0 ? S_OK : S_FALSE;
232 /***********************************************************************
233 * DllRegisterServer (MSI.@)
235 HRESULT WINAPI DllRegisterServer(void)
237 return __wine_register_resources( msi_hInstance );
240 /***********************************************************************
241 * DllUnregisterServer (MSI.@)
243 HRESULT WINAPI DllUnregisterServer(void)
245 return __wine_unregister_resources( msi_hInstance );