msi_main.c 5.61 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
/*
 * 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

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

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msi);

static LONG dll_count;

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

53

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

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

/******************************************************************
68
 *      DllMain
69 70 71 72 73 74 75 76
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        msi_hInstance = hinstDLL;
        DisableThreadLibraryCalls(hinstDLL);
77
        IsWow64Process( GetCurrentProcess(), &is_wow64 );
78 79
        break;
    case DLL_PROCESS_DETACH:
80
        if (lpvReserved) break;
81
        msi_dialog_unregister_class();
82
        msi_free_handle_table();
83
        free( gszLogFile );
84
        release_typelib();
85 86 87 88 89
        break;
    }
    return TRUE;
}

90 91
struct class_factory
{
92
    IClassFactory IClassFactory_iface;
93 94
    HRESULT (*create_object)( IUnknown *, void ** );
};
95

96
static inline struct class_factory *impl_from_IClassFactory(IClassFactory *iface)
97
{
98
    return CONTAINING_RECORD(iface, struct class_factory, IClassFactory_iface);
99 100
}

101 102 103
static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
                REFIID riid,LPVOID *ppobj)
{
104
    struct class_factory *This = impl_from_IClassFactory(iface);
105 106 107 108 109 110 111 112 113 114

    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;
    }
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    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)
{
133
    struct class_factory *This = impl_from_IClassFactory(iface);
134 135
    IUnknown *unk = NULL;
    HRESULT r;
136

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

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

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
};

169
static struct class_factory MsiServer_CF = { { &MsiCF_Vtbl }, create_msiserver };
170 171 172 173 174 175 176 177

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

178
    if ( IsEqualCLSID (rclsid, &CLSID_MsiInstaller) )
179
    {
180
        *ppv = &MsiServer_CF;
181 182 183
        return S_OK;
    }

184 185 186 187
    if( IsEqualCLSID (rclsid, &CLSID_MsiServerMessage) ||
        IsEqualCLSID (rclsid, &CLSID_MsiServer) ||
        IsEqualCLSID (rclsid, &CLSID_PSFactoryBuffer) ||
        IsEqualCLSID (rclsid, &CLSID_MsiServerX3) )
188 189 190 191
    {
        FIXME("create %s object\n", debugstr_guid( rclsid ));
    }

192 193 194 195 196 197 198 199 200 201
    return CLASS_E_CLASSNOTAVAILABLE;
}

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

202
    if (pdvi->cbSize < sizeof(DLLVERSIONINFO))
203 204 205 206 207
        return E_INVALIDARG;

    pdvi->dwMajorVersion = MSI_MAJORVERSION;
    pdvi->dwMinorVersion = MSI_MINORVERSION;
    pdvi->dwBuildNumber = MSI_BUILDNUMBER;
208
    pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
209 210 211 212 213 214 215 216 217 218 219

    return S_OK;
}

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