Sync up with trunk r61578.
[reactos.git] / dll / directx / wine / dplayx / dpclassfactory.c
1 /* COM class factory for direct play lobby interfaces.
2 *
3 * Copyright 1999, 2000 Peter Hunnisett
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * 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 #define COBJMACROS
24
25 //#include "windef.h"
26 //#include "winbase.h"
27 //#include "objbase.h"
28 //#include "winerror.h"
29 #include <wine/debug.h>
30 //#include "dplay.h"
31 //#include "dplobby.h"
32 //#include "initguid.h"
33 #include "dplay_global.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
36
37
38 typedef struct
39 {
40 IClassFactory IClassFactory_iface;
41 HRESULT (*createinstance)(REFIID riid, void **ppv);
42 } IClassFactoryImpl;
43
44 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
45 {
46 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
47 }
48
49 static HRESULT WINAPI IClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
50 void **ppv)
51 {
52 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
53
54 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
55 {
56 *ppv = iface;
57 IClassFactory_AddRef(iface);
58 return S_OK;
59 }
60
61 *ppv = NULL;
62 WARN("no interface for %s\n", debugstr_guid(riid));
63 return E_NOINTERFACE;
64 }
65
66 static ULONG WINAPI IClassFactoryImpl_AddRef(IClassFactory *iface)
67 {
68 return 2; /* non-heap based object */
69 }
70
71 static ULONG WINAPI IClassFactoryImpl_Release(IClassFactory *iface)
72 {
73 return 1; /* non-heap based object */
74 }
75
76 static HRESULT WINAPI IClassFactoryImpl_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
77 REFIID riid, void **ppv)
78 {
79 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80
81 TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);
82
83 if (pOuter)
84 return CLASS_E_NOAGGREGATION;
85
86 return This->createinstance(riid, ppv);
87 }
88
89 static HRESULT WINAPI IClassFactoryImpl_LockServer(IClassFactory *iface, BOOL dolock)
90 {
91 FIXME("(%p)->(%d),stub!\n", iface, dolock);
92 return S_OK;
93 }
94
95 static const IClassFactoryVtbl cf_vt = {
96 IClassFactoryImpl_QueryInterface,
97 IClassFactoryImpl_AddRef,
98 IClassFactoryImpl_Release,
99 IClassFactoryImpl_CreateInstance,
100 IClassFactoryImpl_LockServer
101 };
102
103 static IClassFactoryImpl dplay_cf = {{&cf_vt}, dplay_create};
104 static IClassFactoryImpl dplaylobby_cf = {{&cf_vt}, dplobby_create};
105
106
107 /*******************************************************************************
108 * DllGetClassObject [DPLAYX.@]
109 * Retrieves DP or DPL class object from a DLL object
110 *
111 * NOTES
112 * Docs say returns STDAPI
113 *
114 * PARAMS
115 * rclsid [I] CLSID for the class object
116 * riid [I] Reference to identifier of interface for class object
117 * ppv [O] Address of variable to receive interface pointer for riid
118 *
119 * RETURNS
120 * Success: S_OK
121 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
122 * E_UNEXPECTED
123 */
124 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
125 {
126 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
127
128 if (IsEqualCLSID(&CLSID_DirectPlay, rclsid))
129 return IClassFactory_QueryInterface(&dplay_cf.IClassFactory_iface, riid, ppv);
130
131 if (IsEqualCLSID(&CLSID_DirectPlayLobby, rclsid))
132 return IClassFactory_QueryInterface(&dplaylobby_cf.IClassFactory_iface, riid, ppv);
133
134 FIXME("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
135 return CLASS_E_CLASSNOTAVAILABLE;
136 }