[AMSTREAM] We don't need to define WIDL_C_INLINE_WRAPPERS here anymore.
[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 "dplayx_global.h"
21
22 typedef struct
23 {
24 IClassFactory IClassFactory_iface;
25 HRESULT (*createinstance)(REFIID riid, void **ppv);
26 } IClassFactoryImpl;
27
28 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
29 {
30 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
31 }
32
33 static HRESULT WINAPI IClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
34 void **ppv)
35 {
36 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
37
38 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
39 {
40 *ppv = iface;
41 IClassFactory_AddRef(iface);
42 return S_OK;
43 }
44
45 *ppv = NULL;
46 WARN("no interface for %s\n", debugstr_guid(riid));
47 return E_NOINTERFACE;
48 }
49
50 static ULONG WINAPI IClassFactoryImpl_AddRef(IClassFactory *iface)
51 {
52 return 2; /* non-heap based object */
53 }
54
55 static ULONG WINAPI IClassFactoryImpl_Release(IClassFactory *iface)
56 {
57 return 1; /* non-heap based object */
58 }
59
60 static HRESULT WINAPI IClassFactoryImpl_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
61 REFIID riid, void **ppv)
62 {
63 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
64
65 TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);
66
67 if (pOuter)
68 return CLASS_E_NOAGGREGATION;
69
70 return This->createinstance(riid, ppv);
71 }
72
73 static HRESULT WINAPI IClassFactoryImpl_LockServer(IClassFactory *iface, BOOL dolock)
74 {
75 FIXME("(%p)->(%d),stub!\n", iface, dolock);
76 return S_OK;
77 }
78
79 static const IClassFactoryVtbl cf_vt = {
80 IClassFactoryImpl_QueryInterface,
81 IClassFactoryImpl_AddRef,
82 IClassFactoryImpl_Release,
83 IClassFactoryImpl_CreateInstance,
84 IClassFactoryImpl_LockServer
85 };
86
87 static IClassFactoryImpl dplay_cf = {{&cf_vt}, dplay_create};
88 static IClassFactoryImpl dplaylobby_cf = {{&cf_vt}, dplobby_create};
89
90
91 /*******************************************************************************
92 * DllGetClassObject [DPLAYX.@]
93 * Retrieves DP or DPL class object from a DLL object
94 *
95 * NOTES
96 * Docs say returns STDAPI
97 *
98 * PARAMS
99 * rclsid [I] CLSID for the class object
100 * riid [I] Reference to identifier of interface for class object
101 * ppv [O] Address of variable to receive interface pointer for riid
102 *
103 * RETURNS
104 * Success: S_OK
105 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
106 * E_UNEXPECTED
107 */
108 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
109 {
110 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
111
112 if (IsEqualCLSID(&CLSID_DirectPlay, rclsid))
113 return IClassFactory_QueryInterface(&dplay_cf.IClassFactory_iface, riid, ppv);
114
115 if (IsEqualCLSID(&CLSID_DirectPlayLobby, rclsid))
116 return IClassFactory_QueryInterface(&dplaylobby_cf.IClassFactory_iface, riid, ppv);
117
118 FIXME("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
119 return CLASS_E_CLASSNOTAVAILABLE;
120 }