main.c 5.84 KB
Newer Older
Jacek Caban's avatar
Jacek Caban committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright 2007 Jacek Caban 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 "config.h"

#include <stdarg.h>
22
#include <stdio.h>
Jacek Caban's avatar
Jacek Caban committed
23

24 25
#define COBJMACROS

Jacek Caban's avatar
Jacek Caban committed
26 27
#include "windef.h"
#include "winbase.h"
28 29 30 31 32 33
#include "wingdi.h"
#include "winuser.h"
#include "winreg.h"
#include "advpub.h"
#include "ole2.h"
#include "dimm.h"
Jacek Caban's avatar
Jacek Caban committed
34 35 36 37 38

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msimtf);

39 40
static HINSTANCE msimtf_instance;

41 42 43 44 45 46
static HRESULT CActiveIMM_Create(IUnknown *outer, REFIID riid, void **ppv)
{
    FIXME("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
    return E_NOINTERFACE;
}

Jacek Caban's avatar
Jacek Caban committed
47 48 49 50 51 52 53 54 55 56
/******************************************************************
 *              DllMain (msimtf.@)
 */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    switch(fdwReason)
    {
    case DLL_WINE_PREATTACH:
        return FALSE;  /* prefer native version */
    case DLL_PROCESS_ATTACH:
57
        msimtf_instance = hInstDLL;
Jacek Caban's avatar
Jacek Caban committed
58 59 60 61 62 63 64 65
        DisableThreadLibraryCalls(hInstDLL);
        break;
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
typedef struct {
    const IClassFactoryVtbl *lpClassFactoryVtbl;

    HRESULT (*cf)(IUnknown*,REFIID,void**);
} ClassFactory;

static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface,
        REFIID riid, void **ppv)
{
    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(IID_IUnknown %p)\n", ppv);
        *ppv = iface;
    }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
        TRACE("IID_IClassFactory %p)\n", ppv);
        *ppv = iface;
    }

    if(*ppv) {
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
    }

    FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
    return E_NOINTERFACE;
}

static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
    return 2;
}

static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
    return 1;
}

static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
        IUnknown *pOuter, REFIID riid, void **ppv)
{
    ClassFactory *This = (ClassFactory*)iface;
    return This->cf(pOuter, riid, ppv);
}

static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
    FIXME("(%d)\n", dolock);
    return S_OK;
}

static const IClassFactoryVtbl ClassFactoryVtbl = {
    ClassFactory_QueryInterface,
    ClassFactory_AddRef,
    ClassFactory_Release,
    ClassFactory_CreateInstance,
    ClassFactory_LockServer
};

Jacek Caban's avatar
Jacek Caban committed
125 126 127 128 129
/******************************************************************
 *		DllGetClassObject (msimtf.@)
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
130 131 132 133 134 135 136 137 138 139 140
    if(IsEqualGUID(&CLSID_CActiveIMM, rclsid)) {
        static ClassFactory cf = {
            &ClassFactoryVtbl,
            CActiveIMM_Create
        };

        TRACE("CLSID_CActiveIMM\n");

        return IClassFactory_QueryInterface((IClassFactory*)&cf, riid, ppv);
    }

Jacek Caban's avatar
Jacek Caban committed
141 142 143 144 145 146 147 148 149 150 151 152 153
    FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
    return CLASS_E_CLASSNOTAVAILABLE;
}

/******************************************************************
 *              DllCanUnloadNow (msimtf.@)
 */
HRESULT WINAPI DllCanUnloadNow(void)
{
    FIXME("()\n");
    return S_FALSE;
}

154 155 156 157 158 159 160 161 162 163 164 165 166
#define INF_SET_CLSID(clsid)                  \
    do                                        \
    {                                         \
        static CHAR name[] = "CLSID_" #clsid; \
                                              \
        pse[i].pszName = name;                \
        clsids[i++] = &CLSID_ ## clsid;       \
    } while (0)

static HRESULT register_server(BOOL doregister)
{
    HRESULT hres;
    HMODULE hAdvpack;
167
    HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    STRTABLEA strtable;
    STRENTRYA pse[1];
    static CLSID const *clsids[34];
    int i = 0;

    static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};

    INF_SET_CLSID(CActiveIMM);

    for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
        pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
        sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
                clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
                clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
                clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
    }

    strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
    strtable.pse = pse;

    hAdvpack = LoadLibraryW(wszAdvpack);
189
    pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
190 191 192 193 194 195 196 197 198 199 200

    hres = pRegInstall(msimtf_instance, doregister ? "RegisterDll" : "UnregisterDll", &strtable);

    for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
        HeapFree(GetProcessHeap(), 0, pse[i].pszValue);

    return hres;
}

#undef INF_SET_CLSID

Jacek Caban's avatar
Jacek Caban committed
201 202 203 204 205
/***********************************************************************
 *          DllRegisterServer (msimtf.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
206
    return register_server(TRUE);
Jacek Caban's avatar
Jacek Caban committed
207 208 209 210 211 212 213
}

/***********************************************************************
 *          DllUnregisterServer (msimtf.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
214
    return register_server(FALSE);
Jacek Caban's avatar
Jacek Caban committed
215
}