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"
33 #include "ddrawex_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
37 static HINSTANCE instance;
39 /******************************************************************************
40 * DirectDraw ClassFactory implementation
41 ******************************************************************************/
44 IClassFactory IClassFactory_iface;
46 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
49 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 /*******************************************************************************
55 * IDirectDrawClassFactory::QueryInterface
57 *******************************************************************************/
58 static HRESULT WINAPI IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
61 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), obj);
63 if (IsEqualGUID(riid, &IID_IUnknown)
64 || IsEqualGUID(riid, &IID_IClassFactory))
66 IClassFactory_AddRef(iface);
71 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
77 /*******************************************************************************
78 * IDirectDrawClassFactory::AddRef
80 *******************************************************************************/
81 static ULONG WINAPI IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
83 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
84 ULONG ref = InterlockedIncrement(&This->ref);
86 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
91 /*******************************************************************************
92 * IDirectDrawClassFactory::Release
94 *******************************************************************************/
95 static ULONG WINAPI IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
97 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98 ULONG ref = InterlockedDecrement(&This->ref);
100 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
103 HeapFree(GetProcessHeap(), 0, This);
109 /*******************************************************************************
110 * IDirectDrawClassFactory::CreateInstance
112 *******************************************************************************/
113 static HRESULT WINAPI IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
114 IUnknown *UnkOuter, REFIID riid, void **obj)
116 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
118 TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
120 return This->pfnCreateInstance(UnkOuter, riid, obj);
123 /*******************************************************************************
124 * IDirectDrawClassFactory::LockServer
126 *******************************************************************************/
127 static HRESULT WINAPI IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
129 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
131 FIXME("(%p)->(%d),stub!\n",This,dolock);
137 /*******************************************************************************
138 * The class factory VTable
139 *******************************************************************************/
140 static const IClassFactoryVtbl IClassFactory_Vtbl =
142 IDirectDrawClassFactoryImpl_QueryInterface,
143 IDirectDrawClassFactoryImpl_AddRef,
144 IDirectDrawClassFactoryImpl_Release,
145 IDirectDrawClassFactoryImpl_CreateInstance,
146 IDirectDrawClassFactoryImpl_LockServer
150 /******************************************************************************
151 * DirectDrawFactory implementation
152 ******************************************************************************/
155 IDirectDrawFactory IDirectDrawFactory_iface;
157 } IDirectDrawFactoryImpl;
159 static inline IDirectDrawFactoryImpl *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
161 return CONTAINING_RECORD(iface, IDirectDrawFactoryImpl, IDirectDrawFactory_iface);
164 /*******************************************************************************
165 * IDirectDrawFactory::QueryInterface
167 *******************************************************************************/
168 static HRESULT WINAPI IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface, REFIID riid,
171 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), obj);
173 if (IsEqualGUID(riid, &IID_IUnknown)
174 || IsEqualGUID(riid, &IID_IDirectDrawFactory))
176 IDirectDrawFactory_AddRef(iface);
181 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
184 return E_NOINTERFACE;
187 /*******************************************************************************
188 * IDirectDrawFactory::AddRef
190 *******************************************************************************/
191 static ULONG WINAPI IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
193 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
194 ULONG ref = InterlockedIncrement(&This->ref);
196 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
201 /*******************************************************************************
202 * IDirectDrawFactory::Release
204 *******************************************************************************/
205 static ULONG WINAPI IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
207 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
208 ULONG ref = InterlockedDecrement(&This->ref);
210 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
213 HeapFree(GetProcessHeap(), 0, This);
218 /*******************************************************************************
219 * IDirectDrawFactoryImpl_DirectDrawEnumerate
220 *******************************************************************************/
221 static HRESULT WINAPI
222 IDirectDrawFactoryImpl_DirectDrawEnumerate(IDirectDrawFactory* iface,
223 LPDDENUMCALLBACKW lpCallback,
231 /*******************************************************************************
232 * Direct Draw Factory VTable
233 *******************************************************************************/
234 static const IDirectDrawFactoryVtbl IDirectDrawFactory_Vtbl =
236 IDirectDrawFactoryImpl_QueryInterface,
237 IDirectDrawFactoryImpl_AddRef,
238 IDirectDrawFactoryImpl_Release,
239 IDirectDrawFactoryImpl_CreateDirectDraw,
240 IDirectDrawFactoryImpl_DirectDrawEnumerate,
243 /***********************************************************************
244 * CreateDirectDrawFactory
246 ***********************************************************************/
248 CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
251 IDirectDrawFactoryImpl *This = NULL;
253 TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
255 if (UnkOuter != NULL)
256 return CLASS_E_NOAGGREGATION;
258 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawFactoryImpl));
262 ERR("Out of memory when creating DirectDraw\n");
263 return E_OUTOFMEMORY;
266 This->IDirectDrawFactory_iface.lpVtbl = &IDirectDrawFactory_Vtbl;
268 hr = IDirectDrawFactory_QueryInterface(&This->IDirectDrawFactory_iface, iid, obj);
271 HeapFree(GetProcessHeap(), 0, This);
277 /*******************************************************************************
278 * DllCanUnloadNow [DDRAWEX.@] Determines whether the DLL is in use.
280 HRESULT WINAPI DllCanUnloadNow(void)
286 /*******************************************************************************
287 * DllGetClassObject [DDRAWEX.@]
289 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
291 IClassFactoryImpl *factory;
293 TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
295 if (!IsEqualGUID( &IID_IClassFactory, riid)
296 && !IsEqualGUID( &IID_IUnknown, riid))
297 return E_NOINTERFACE;
299 if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
301 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
302 return CLASS_E_CLASSNOTAVAILABLE;
305 factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
306 if (factory == NULL) return E_OUTOFMEMORY;
308 factory->IClassFactory_iface.lpVtbl = &IClassFactory_Vtbl;
311 factory->pfnCreateInstance = CreateDirectDrawFactory;
319 /***********************************************************************
322 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
326 case DLL_PROCESS_ATTACH:
328 DisableThreadLibraryCalls( hInstDLL );
334 /***********************************************************************
335 * DllRegisterServer (DDRAWEX.@)
337 HRESULT WINAPI DllRegisterServer(void)
339 return __wine_register_resources( instance );
342 /***********************************************************************
343 * DllUnregisterServer (DDRAWEX.@)
345 HRESULT WINAPI DllUnregisterServer(void)
347 return __wine_unregister_resources( instance );