dpclassfactory.c 4.03 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
#include "dplay_global.h"
35

36
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
37 38 39 40


typedef struct
{
41
    IClassFactory IClassFactory_iface;
42
    HRESULT (*createinstance)(REFIID riid, void **ppv);
43 44
} IClassFactoryImpl;

45 46 47 48 49
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

50
static HRESULT WINAPI IClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
51
        void **ppv)
52
{
53
    TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
54

55 56 57 58 59 60
    if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
    {
        *ppv = iface;
        IClassFactory_AddRef(iface);
        return S_OK;
    }
61

62 63 64
    *ppv = NULL;
    WARN("no interface for %s\n", debugstr_guid(riid));
    return E_NOINTERFACE;
65 66
}

67 68
static ULONG WINAPI IClassFactoryImpl_AddRef(IClassFactory *iface)
{
69
    return 2; /* non-heap based object */
70 71
}

72 73
static ULONG WINAPI IClassFactoryImpl_Release(IClassFactory *iface)
{
74
    return 1; /* non-heap based object */
75 76
}

77
static HRESULT WINAPI IClassFactoryImpl_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
78
        REFIID riid, void **ppv)
79
{
80
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
81

82
    TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);
83

84 85
    if (pOuter)
        return CLASS_E_NOAGGREGATION;
86

87
    return This->createinstance(riid, ppv);
88 89
}

90 91
static HRESULT WINAPI IClassFactoryImpl_LockServer(IClassFactory *iface, BOOL dolock)
{
92 93
    FIXME("(%p)->(%d),stub!\n", iface, dolock);
    return S_OK;
94 95
}

96
static const IClassFactoryVtbl cf_vt = {
97 98 99 100 101
    IClassFactoryImpl_QueryInterface,
    IClassFactoryImpl_AddRef,
    IClassFactoryImpl_Release,
    IClassFactoryImpl_CreateInstance,
    IClassFactoryImpl_LockServer
102 103
};

104
static IClassFactoryImpl dplay_cf = {{&cf_vt}, dplay_create};
105
static IClassFactoryImpl dplaylobby_cf = {{&cf_vt}, dplobby_create};
106 107 108


/*******************************************************************************
109
 * DllGetClassObject [DPLAYX.@]
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
 * 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
 */
125
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
126
{
127
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
128

129 130
    if (IsEqualCLSID(&CLSID_DirectPlay, rclsid))
        return IClassFactory_QueryInterface(&dplay_cf.IClassFactory_iface, riid, ppv);
131

132 133
    if (IsEqualCLSID(&CLSID_DirectPlayLobby, rclsid))
        return IClassFactory_QueryInterface(&dplaylobby_cf.IClassFactory_iface, riid, ppv);
134

135
    FIXME("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
136 137
    return CLASS_E_CLASSNOTAVAILABLE;
}