msi_main.c 6.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2006 Mike McCormack for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#define COBJMACROS
#define NONAMELESSUNION

#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "shlwapi.h"
30
#include "oleauto.h"
31
#include "rpcproxy.h"
32
#include "msipriv.h"
33
#include "msiserver.h"
34 35 36 37 38 39 40 41

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msi);

static LONG dll_count;

/* the UI level */
42 43 44 45 46 47 48
INSTALLUILEVEL           gUILevel         = INSTALLUILEVEL_BASIC;
HWND                     gUIhwnd          = 0;
INSTALLUI_HANDLERA       gUIHandlerA      = NULL;
INSTALLUI_HANDLERW       gUIHandlerW      = NULL;
INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
DWORD                    gUIFilter        = 0;
LPVOID                   gUIContext       = NULL;
49
WCHAR                   *gszLogFile       = NULL;
50 51
HINSTANCE msi_hInstance;

52

53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*
 * Dll lifetime tracking declaration
 */
static void LockModule(void)
{
    InterlockedIncrement(&dll_count);
}

static void UnlockModule(void)
{
    InterlockedDecrement(&dll_count);
}

/******************************************************************
67
 *      DllMain
68 69 70 71 72 73 74 75 76 77 78
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        msi_hInstance = hinstDLL;
        DisableThreadLibraryCalls(hinstDLL);
        break;
    case DLL_PROCESS_DETACH:
        msi_dialog_unregister_class();
79
        msi_free_handle_table();
80
        msi_free( gszLogFile );
81 82 83 84 85
        break;
    }
    return TRUE;
}

86
typedef struct tagIClassFactoryImpl {
87
    IClassFactory IClassFactory_iface;
88 89 90
    HRESULT (*create_object)( IUnknown*, LPVOID* );
} IClassFactoryImpl;

91 92 93 94 95
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

96 97 98
static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
                REFIID riid,LPVOID *ppobj)
{
99
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
100 101 102 103 104 105 106 107 108 109

    TRACE("%p %s %p\n",This,debugstr_guid(riid),ppobj);

    if( IsEqualCLSID( riid, &IID_IUnknown ) ||
        IsEqualCLSID( riid, &IID_IClassFactory ) )
    {
        IClassFactory_AddRef( iface );
        *ppobj = iface;
        return S_OK;
    }
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    return E_NOINTERFACE;
}

static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
{
    LockModule();
    return 2;
}

static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
{
    UnlockModule();
    return 1;
}

static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
    LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
{
128
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
129 130
    IUnknown *unk = NULL;
    HRESULT r;
131

132 133
    TRACE("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);

Mike McCormack's avatar
Mike McCormack committed
134
    r = This->create_object( pOuter, (LPVOID*) &unk );
135 136 137 138 139 140
    if (SUCCEEDED(r))
    {
        r = IUnknown_QueryInterface( unk, riid, ppobj );
        IUnknown_Release( unk );
    }
    return r;
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
}

static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
{
    TRACE("%p %d\n", iface, dolock);

    if (dolock)
        LockModule();
    else
        UnlockModule();

    return S_OK;
}

static const IClassFactoryVtbl MsiCF_Vtbl =
{
    MsiCF_QueryInterface,
    MsiCF_AddRef,
    MsiCF_Release,
    MsiCF_CreateInstance,
    MsiCF_LockServer
};

164 165 166
static IClassFactoryImpl MsiServer_CF = { { &MsiCF_Vtbl }, create_msiserver };
static IClassFactoryImpl WineMsiCustomRemote_CF = { { &MsiCF_Vtbl }, create_msi_custom_remote };
static IClassFactoryImpl WineMsiRemotePackage_CF = { { &MsiCF_Vtbl }, create_msi_remote_package };
167 168 169 170 171 172 173 174

/******************************************************************
 * DllGetClassObject          [MSI.@]
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
    TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);

175
    if ( IsEqualCLSID (rclsid, &CLSID_MsiInstaller) )
176
    {
177
        *ppv = &MsiServer_CF;
178 179 180
        return S_OK;
    }

181
    if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemoteCustomAction) )
182
    {
183
        *ppv = &WineMsiCustomRemote_CF;
184
        return S_OK;
185
    }
186

187
    if ( IsEqualCLSID (rclsid, &CLSID_WineMsiRemotePackage) )
188
    {
189
        *ppv = &WineMsiRemotePackage_CF;
190 191 192
        return S_OK;
    }

193 194 195 196
    if( IsEqualCLSID (rclsid, &CLSID_MsiServerMessage) ||
        IsEqualCLSID (rclsid, &CLSID_MsiServer) ||
        IsEqualCLSID (rclsid, &CLSID_PSFactoryBuffer) ||
        IsEqualCLSID (rclsid, &CLSID_MsiServerX3) )
197 198 199 200
    {
        FIXME("create %s object\n", debugstr_guid( rclsid ));
    }

201 202 203 204 205 206 207 208 209 210
    return CLASS_E_CLASSNOTAVAILABLE;
}

/******************************************************************
 * DllGetVersion              [MSI.@]
 */
HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *pdvi)
{
    TRACE("%p\n",pdvi);

211
    if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
212 213 214 215 216
        return E_INVALIDARG;

    pdvi->dwMajorVersion = MSI_MAJORVERSION;
    pdvi->dwMinorVersion = MSI_MINORVERSION;
    pdvi->dwBuildNumber = MSI_BUILDNUMBER;
217
    pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
218 219 220 221 222 223 224 225 226 227 228

    return S_OK;
}

/******************************************************************
 * DllCanUnloadNow            [MSI.@]
 */
HRESULT WINAPI DllCanUnloadNow(void)
{
    return dll_count == 0 ? S_OK : S_FALSE;
}
229 230

/***********************************************************************
231
 *  DllRegisterServer (MSI.@)
232 233 234 235 236 237 238
 */
HRESULT WINAPI DllRegisterServer(void)
{
    return __wine_register_resources( msi_hInstance, NULL );
}

/***********************************************************************
239
 *  DllUnregisterServer (MSI.@)
240 241 242 243 244
 */
HRESULT WINAPI DllUnregisterServer(void)
{
    return __wine_unregister_resources( msi_hInstance, NULL );
}