main.c 3.43 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
/*
 * Network Configuration Objects implementation
 *
 * Copyright 2013 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 "ole2.h"
#include "rpcproxy.h"
Austin English's avatar
Austin English committed
28 29
#include "wine/debug.h"

30 31 32
#include "netcfgx.h"
#include "netcfg_private.h"

Austin English's avatar
Austin English committed
33 34
WINE_DEFAULT_DEBUG_CHANNEL(netcfgx);

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 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
typedef HRESULT (*ClassFactoryCreateInstanceFunc)(IUnknown **);

typedef struct netcfgcf
{
    IClassFactory    IClassFactory_iface;
    ClassFactoryCreateInstanceFunc fnCreateInstance;
} netcfgcf;

static inline netcfgcf *impl_from_IClassFactory( IClassFactory *iface )
{
    return CONTAINING_RECORD(iface, netcfgcf, IClassFactory_iface);
}

static HRESULT WINAPI netcfgcf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj )
{
    TRACE("%s %p\n", debugstr_guid(riid), ppobj);

    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IClassFactory))
    {
        IClassFactory_AddRef( iface );
        *ppobj = iface;
        return S_OK;
    }

    ERR("interface %s not implemented\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

static ULONG WINAPI netcfgcf_AddRef(IClassFactory *iface )
{
    TRACE("%p\n", iface);

    return 2;
}

static ULONG WINAPI netcfgcf_Release(IClassFactory *iface )
{
    TRACE("%p\n", iface);

    return 1;
}

static HRESULT WINAPI netcfgcf_CreateInstance(IClassFactory *iface,LPUNKNOWN pOuter,
                            REFIID riid, LPVOID *ppobj )
{
    netcfgcf *This = impl_from_IClassFactory( iface );
    HRESULT hr;
    IUnknown *punk;

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

    *ppobj = NULL;

    if (pOuter)
        return CLASS_E_NOAGGREGATION;

    hr = This->fnCreateInstance( &punk );
    if (SUCCEEDED(hr))
    {
        hr = IUnknown_QueryInterface( punk, riid, ppobj );

        IUnknown_Release( punk );
    }
    else
    {
        WARN("Cannot create an instance object. 0x%08x\n", hr);
    }
    return hr;
}

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

static const struct IClassFactoryVtbl netcfgcf_vtbl =
{
    netcfgcf_QueryInterface,
    netcfgcf_AddRef,
    netcfgcf_Release,
    netcfgcf_CreateInstance,
    netcfgcf_LockServer
};

static netcfgcf netconfigcf = { {&netcfgcf_vtbl}, INetCfg_CreateInstance };

123 124
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
125 126 127 128 129 130 131 132 133 134 135
    IClassFactory *cf = NULL;

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

    if(IsEqualCLSID(rclsid, &CLSID_CNetCfg))
    {
        cf = &netconfigcf.IClassFactory_iface;
    }

    if(!cf)
        return CLASS_E_CLASSNOTAVAILABLE;
136

137
    return IClassFactory_QueryInterface(cf, riid, ppv);
138
}