winspool/tests: Add tests for GetFormA().
[wine.git] / dlls / ddrawex / main.c
blob8ecc24f824cad70aae315f23eb669f5b17dd03b4
1 /* DirectDrawEx
3 * Copyright 2006 Ulrich Czekalla
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.
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.
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
21 #include "wine/debug.h"
23 #define COBJMACROS
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "objbase.h"
28 #include "rpcproxy.h"
30 #include "ddraw.h"
32 #include "initguid.h"
33 #include "ddrawex_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
37 struct ddrawex_class_factory
39 IClassFactory IClassFactory_iface;
40 LONG ref;
41 HRESULT (*pfnCreateInstance)(IUnknown *outer, REFIID iid, void **out);
44 static inline struct ddrawex_class_factory *impl_from_IClassFactory(IClassFactory *iface)
46 return CONTAINING_RECORD(iface, struct ddrawex_class_factory, IClassFactory_iface);
49 static HRESULT WINAPI ddrawex_class_factory_QueryInterface(IClassFactory *iface, REFIID riid, void **out)
51 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
53 if (IsEqualGUID(riid, &IID_IClassFactory)
54 || IsEqualGUID(riid, &IID_IUnknown))
56 IClassFactory_AddRef(iface);
57 *out = iface;
58 return S_OK;
61 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
63 *out = NULL;
64 return E_NOINTERFACE;
67 static ULONG WINAPI ddrawex_class_factory_AddRef(IClassFactory *iface)
69 struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
70 ULONG refcount = InterlockedIncrement(&factory->ref);
72 TRACE("%p increasing refcount to %u.\n", iface, refcount);
74 return refcount;
77 static ULONG WINAPI ddrawex_class_factory_Release(IClassFactory *iface)
79 struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
80 ULONG refcount = InterlockedDecrement(&factory->ref);
82 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
84 if (!refcount)
85 heap_free(factory);
87 return refcount;
90 static HRESULT WINAPI ddrawex_class_factory_CreateInstance(IClassFactory *iface,
91 IUnknown *outer_unknown, REFIID riid, void **out)
93 struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
95 TRACE("iface %p, outer_unknown %p, riid %s, out %p.\n",
96 iface, outer_unknown, debugstr_guid(riid), out);
98 return factory->pfnCreateInstance(outer_unknown, riid, out);
101 static HRESULT WINAPI ddrawex_class_factory_LockServer(IClassFactory *iface, BOOL dolock)
103 FIXME("iface %p, dolock %#x stub!\n", iface, dolock);
105 return S_OK;
108 static const IClassFactoryVtbl ddrawex_class_factory_vtbl =
110 ddrawex_class_factory_QueryInterface,
111 ddrawex_class_factory_AddRef,
112 ddrawex_class_factory_Release,
113 ddrawex_class_factory_CreateInstance,
114 ddrawex_class_factory_LockServer,
117 struct ddrawex_factory
119 IDirectDrawFactory IDirectDrawFactory_iface;
120 LONG ref;
123 static inline struct ddrawex_factory *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
125 return CONTAINING_RECORD(iface, struct ddrawex_factory, IDirectDrawFactory_iface);
128 static HRESULT WINAPI ddrawex_factory_QueryInterface(IDirectDrawFactory *iface, REFIID riid, void **out)
130 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
132 if (IsEqualGUID(riid, &IID_IDirectDrawFactory)
133 || IsEqualGUID(riid, &IID_IUnknown))
135 IDirectDrawFactory_AddRef(iface);
136 *out = iface;
137 return S_OK;
140 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
142 *out = NULL;
143 return E_NOINTERFACE;
146 static ULONG WINAPI ddrawex_factory_AddRef(IDirectDrawFactory *iface)
148 struct ddrawex_factory *factory = impl_from_IDirectDrawFactory(iface);
149 ULONG refcount = InterlockedIncrement(&factory->ref);
151 TRACE("%p increasing refcount to %u.\n", iface, refcount);
153 return refcount;
156 static ULONG WINAPI ddrawex_factory_Release(IDirectDrawFactory *iface)
158 struct ddrawex_factory *factory = impl_from_IDirectDrawFactory(iface);
159 ULONG refcount = InterlockedDecrement(&factory->ref);
161 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
163 if (!refcount)
164 heap_free(factory);
166 return refcount;
169 static HRESULT WINAPI ddrawex_factory_DirectDrawEnumerate(IDirectDrawFactory *iface,
170 LPDDENUMCALLBACKW cb, void *ctx)
172 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
174 return E_FAIL;
177 static const IDirectDrawFactoryVtbl ddrawex_factory_vtbl =
179 ddrawex_factory_QueryInterface,
180 ddrawex_factory_AddRef,
181 ddrawex_factory_Release,
182 ddrawex_factory_CreateDirectDraw,
183 ddrawex_factory_DirectDrawEnumerate,
186 static HRESULT ddrawex_factory_create(IUnknown *outer_unknown, REFIID riid, void **out)
188 struct ddrawex_factory *factory;
189 HRESULT hr;
191 TRACE("outer_unknown %p, riid %s, out %p.\n", outer_unknown, debugstr_guid(riid), out);
193 if (outer_unknown)
194 return CLASS_E_NOAGGREGATION;
196 if (!(factory = heap_alloc_zero(sizeof(*factory))))
197 return E_OUTOFMEMORY;
199 factory->IDirectDrawFactory_iface.lpVtbl = &ddrawex_factory_vtbl;
201 if (FAILED(hr = ddrawex_factory_QueryInterface(&factory->IDirectDrawFactory_iface, riid, out)))
202 heap_free(factory);
204 return hr;
207 /*******************************************************************************
208 * DllGetClassObject [DDRAWEX.@]
210 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **out)
212 struct ddrawex_class_factory *factory;
214 TRACE("rclsid %s, riid %s, out %p.\n", debugstr_guid(rclsid), debugstr_guid(riid), out);
216 if (!IsEqualGUID( &IID_IClassFactory, riid)
217 && !IsEqualGUID( &IID_IUnknown, riid))
218 return E_NOINTERFACE;
220 if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
222 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
223 return CLASS_E_CLASSNOTAVAILABLE;
226 if (!(factory = heap_alloc_zero(sizeof(*factory))))
227 return E_OUTOFMEMORY;
229 factory->IClassFactory_iface.lpVtbl = &ddrawex_class_factory_vtbl;
230 factory->ref = 1;
232 factory->pfnCreateInstance = ddrawex_factory_create;
234 *out = factory;
236 return S_OK;