dpclassfactory.c 4.18 KB
Newer Older
1 2
/* COM class factory for direct play lobby interfaces.
 *
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Copyright 1999, 2000 Peter Hunnisett
 *
 * 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
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 19
 */

20
#include <stdarg.h>
21
#include <string.h>
22 23 24

#define COBJMACROS

25
#include "windef.h"
26
#include "winbase.h"
27
#include "winuser.h"
28
#include "objbase.h"
29
#include "winerror.h"
30
#include "wine/debug.h"
31 32 33
#include "dplay.h"
#include "dplobby.h"
#include "initguid.h"
34 35
#include "dpinit.h"

36
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
37 38 39 40 41 42 43 44 45


/*******************************************************************************
 * DirectPlayLobby ClassFactory
 */

typedef struct
{
    /* IUnknown fields */
46 47
    IClassFactory IClassFactory_iface;
    LONG          ref;
48 49
} IClassFactoryImpl;

50 51 52 53 54
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

55 56
static HRESULT WINAPI
DP_and_DPL_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
57
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
58

59
        FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
60 61 62 63 64 65

        return E_NOINTERFACE;
}

static ULONG WINAPI
DP_and_DPL_AddRef(LPCLASSFACTORY iface) {
66
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
67
        return InterlockedIncrement(&This->ref);
68 69 70
}

static ULONG WINAPI DP_and_DPL_Release(LPCLASSFACTORY iface) {
71
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
72
        /* static class (reference starts @ 1), won't ever be freed */
73
        return InterlockedDecrement(&This->ref);
74 75 76 77 78
}

static HRESULT WINAPI DP_and_DPL_CreateInstance(
        LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
) {
79
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80

81
        TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
82

83
        if ( DPL_CreateInterface( riid, ppobj ) == S_OK )
84 85 86
        {
           return S_OK;
        }
87
        else if ( DP_CreateInterface( riid, ppobj ) == S_OK )
88 89 90 91 92 93 94 95
        {
           return S_OK;
        }

        return E_NOINTERFACE;
}

static HRESULT WINAPI DP_and_DPL_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
96
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
97 98 99 100
        FIXME("(%p)->(%d),stub!\n",This,dolock);
        return S_OK;
}

101
static const IClassFactoryVtbl DP_and_DPL_Vtbl = {
102 103 104 105 106 107 108
        DP_and_DPL_QueryInterface,
        DP_and_DPL_AddRef,
        DP_and_DPL_Release,
        DP_and_DPL_CreateInstance,
        DP_and_DPL_LockServer
};

109
static IClassFactoryImpl DP_and_DPL_CF = {{&DP_and_DPL_Vtbl}, 1 };
110 111 112


/*******************************************************************************
113
 * DllGetClassObject [DPLAYX.@]
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
 * Retrieves DP or DPL class object from a DLL object
 *
 * NOTES
 *    Docs say returns STDAPI
 *
 * PARAMS
 *    rclsid [I] CLSID for the class object
 *    riid   [I] Reference to identifier of interface for class object
 *    ppv    [O] Address of variable to receive interface pointer for riid
 *
 * RETURNS
 *    Success: S_OK
 *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
 *             E_UNEXPECTED
 */
129
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
130
{
131
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
132 133 134

    if ( IsEqualCLSID( riid, &IID_IClassFactory ) )
    {
135
        *ppv = &DP_and_DPL_CF;
136 137 138 139 140
        IClassFactory_AddRef( (IClassFactory*)*ppv );

        return S_OK;
    }

141
    ERR("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
142 143
    return CLASS_E_CLASSNOTAVAILABLE;
}