main.c 3.9 KB
Newer Older
Austin English's avatar
Austin English committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *
 * Copyright 2009 Austin English
 *
 * 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>

22 23
#define COBJMACROS

Austin English's avatar
Austin English committed
24 25
#include "windef.h"
#include "winbase.h"
26 27
#include "objbase.h"
#include "wbemcli.h"
28
#include "wbemprov.h"
29
#include "rpcproxy.h"
30 31 32 33 34 35

#include "wbemprox_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);

36 37
static HINSTANCE instance;

38
struct list *table_list[WBEMPROX_NAMESPACE_LAST];
39

40
typedef HRESULT (*fnCreateInstance)( LPVOID *ppObj );
41 42 43

typedef struct
{
44
    IClassFactory IClassFactory_iface;
45 46 47 48 49
    fnCreateInstance pfnCreateInstance;
} wbemprox_cf;

static inline wbemprox_cf *impl_from_IClassFactory( IClassFactory *iface )
{
50
    return CONTAINING_RECORD(iface, wbemprox_cf, IClassFactory_iface);
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

static HRESULT WINAPI wbemprox_cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
{
    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IClassFactory))
    {
        IClassFactory_AddRef( iface );
        *ppobj = iface;
        return S_OK;
    }
    FIXME("interface %s not implemented\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

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

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

static HRESULT WINAPI wbemprox_cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
                                                  REFIID riid, LPVOID *ppobj )
{
    wbemprox_cf *This = impl_from_IClassFactory( iface );
    HRESULT r;
    IUnknown *punk;

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

    *ppobj = NULL;

    if (pOuter)
        return CLASS_E_NOAGGREGATION;

90
    r = This->pfnCreateInstance( (LPVOID *)&punk );
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    if (FAILED(r))
        return r;

    r = IUnknown_QueryInterface( punk, riid, ppobj );
    IUnknown_Release( punk );
    return r;
}

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

static const struct IClassFactoryVtbl wbemprox_cf_vtbl =
{
    wbemprox_cf_QueryInterface,
    wbemprox_cf_AddRef,
    wbemprox_cf_Release,
    wbemprox_cf_CreateInstance,
    wbemprox_cf_LockServer
};

114
static wbemprox_cf wbem_locator_cf = { { &wbemprox_cf_vtbl }, WbemLocator_create };
115
static wbemprox_cf wbem_context_cf = { { &wbemprox_cf_vtbl }, WbemContext_create };
Austin English's avatar
Austin English committed
116 117 118 119 120 121 122

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{

    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
123
            instance = hinstDLL;
Austin English's avatar
Austin English committed
124
            DisableThreadLibraryCalls(hinstDLL);
125
            init_table_list();
Austin English's avatar
Austin English committed
126 127 128 129 130
            break;
    }

    return TRUE;
}
131 132 133 134 135 136 137

HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
{
    IClassFactory *cf = NULL;

    TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);

138 139
    if (IsEqualGUID( rclsid, &CLSID_WbemLocator ) ||
        IsEqualGUID( rclsid, &CLSID_WbemAdministrativeLocator ))
140
    {
141
       cf = &wbem_locator_cf.IClassFactory_iface;
142
    }
143 144 145 146
    else if (IsEqualGUID( rclsid, &CLSID_WbemContext ))
    {
       cf = &wbem_context_cf.IClassFactory_iface;
    }
147 148 149
    if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
    return IClassFactory_QueryInterface( cf, iid, ppv );
}