po: Update French translation.
[wine/multimedia.git] / dlls / ddrawex / main.c
blob7b32323fa35c7b063a4f394a5fd028ab85921c33
1 /* DirectDrawEx
3 * Copyright 2006 Ulrich Czekalla
5 * This file contains the (internal) driver registration functions,
6 * driver enumeration APIs and DirectDraw creation functions.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/debug.h"
26 #define COBJMACROS
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "objbase.h"
31 #include "rpcproxy.h"
33 #include "ddraw.h"
35 #include "initguid.h"
36 #include "ddrawex_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
40 static HINSTANCE instance;
42 /******************************************************************************
43 * DirectDraw ClassFactory implementation
44 ******************************************************************************/
45 typedef struct
47 IClassFactory IClassFactory_iface;
48 LONG ref;
49 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
50 } IClassFactoryImpl;
52 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
54 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
57 /*******************************************************************************
58 * IDirectDrawClassFactory::QueryInterface
60 *******************************************************************************/
61 static HRESULT WINAPI IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
62 void **obj)
64 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
66 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
68 if (IsEqualGUID(riid, &IID_IUnknown)
69 || IsEqualGUID(riid, &IID_IClassFactory))
71 IClassFactory_AddRef(iface);
72 *obj = This;
73 return S_OK;
76 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
77 return E_NOINTERFACE;
80 /*******************************************************************************
81 * IDirectDrawClassFactory::AddRef
83 *******************************************************************************/
84 static ULONG WINAPI IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
86 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
87 ULONG ref = InterlockedIncrement(&This->ref);
89 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
91 return ref;
94 /*******************************************************************************
95 * IDirectDrawClassFactory::Release
97 *******************************************************************************/
98 static ULONG WINAPI IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
100 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
101 ULONG ref = InterlockedDecrement(&This->ref);
103 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
105 if (ref == 0)
106 HeapFree(GetProcessHeap(), 0, This);
108 return ref;
112 /*******************************************************************************
113 * IDirectDrawClassFactory::CreateInstance
115 *******************************************************************************/
116 static HRESULT WINAPI IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
117 IUnknown *UnkOuter, REFIID riid, void **obj)
119 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
121 TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
123 return This->pfnCreateInstance(UnkOuter, riid, obj);
126 /*******************************************************************************
127 * IDirectDrawClassFactory::LockServer
129 *******************************************************************************/
130 static HRESULT WINAPI IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
132 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
134 FIXME("(%p)->(%d),stub!\n",This,dolock);
136 return S_OK;
140 /*******************************************************************************
141 * The class factory VTable
142 *******************************************************************************/
143 static const IClassFactoryVtbl IClassFactory_Vtbl =
145 IDirectDrawClassFactoryImpl_QueryInterface,
146 IDirectDrawClassFactoryImpl_AddRef,
147 IDirectDrawClassFactoryImpl_Release,
148 IDirectDrawClassFactoryImpl_CreateInstance,
149 IDirectDrawClassFactoryImpl_LockServer
153 /******************************************************************************
154 * DirectDrawFactory implementation
155 ******************************************************************************/
156 typedef struct
158 IDirectDrawFactory IDirectDrawFactory_iface;
159 LONG ref;
160 } IDirectDrawFactoryImpl;
162 static inline IDirectDrawFactoryImpl *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
164 return CONTAINING_RECORD(iface, IDirectDrawFactoryImpl, IDirectDrawFactory_iface);
167 /*******************************************************************************
168 * IDirectDrawFactory::QueryInterface
170 *******************************************************************************/
171 static HRESULT WINAPI IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface, REFIID riid,
172 void **obj)
174 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
176 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
178 if (IsEqualGUID(riid, &IID_IUnknown)
179 || IsEqualGUID(riid, &IID_IDirectDrawFactory))
181 IDirectDrawFactory_AddRef(iface);
182 *obj = This;
183 return S_OK;
186 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
187 return E_NOINTERFACE;
190 /*******************************************************************************
191 * IDirectDrawFactory::AddRef
193 *******************************************************************************/
194 static ULONG WINAPI IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
196 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
197 ULONG ref = InterlockedIncrement(&This->ref);
199 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
201 return ref;
204 /*******************************************************************************
205 * IDirectDrawFactory::Release
207 *******************************************************************************/
208 static ULONG WINAPI IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
210 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
211 ULONG ref = InterlockedDecrement(&This->ref);
213 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
215 if (ref == 0)
216 HeapFree(GetProcessHeap(), 0, This);
218 return ref;
221 /*******************************************************************************
222 * IDirectDrawFactoryImpl_DirectDrawEnumerate
223 *******************************************************************************/
224 static HRESULT WINAPI
225 IDirectDrawFactoryImpl_DirectDrawEnumerate(IDirectDrawFactory* iface,
226 LPDDENUMCALLBACKW lpCallback,
227 LPVOID lpContext)
229 FIXME("Stub!\n");
230 return E_FAIL;
234 /*******************************************************************************
235 * Direct Draw Factory VTable
236 *******************************************************************************/
237 static const IDirectDrawFactoryVtbl IDirectDrawFactory_Vtbl =
239 IDirectDrawFactoryImpl_QueryInterface,
240 IDirectDrawFactoryImpl_AddRef,
241 IDirectDrawFactoryImpl_Release,
242 IDirectDrawFactoryImpl_CreateDirectDraw,
243 IDirectDrawFactoryImpl_DirectDrawEnumerate,
246 /***********************************************************************
247 * CreateDirectDrawFactory
249 ***********************************************************************/
250 static HRESULT
251 CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
253 HRESULT hr;
254 IDirectDrawFactoryImpl *This = NULL;
256 TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
258 if (UnkOuter != NULL)
259 return CLASS_E_NOAGGREGATION;
261 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawFactoryImpl));
263 if(!This)
265 ERR("Out of memory when creating DirectDraw\n");
266 return E_OUTOFMEMORY;
269 This->IDirectDrawFactory_iface.lpVtbl = &IDirectDrawFactory_Vtbl;
271 hr = IDirectDrawFactory_QueryInterface(&This->IDirectDrawFactory_iface, iid, obj);
273 if (FAILED(hr))
274 HeapFree(GetProcessHeap(), 0, This);
276 return hr;
280 /*******************************************************************************
281 * DllCanUnloadNow [DDRAWEX.@] Determines whether the DLL is in use.
283 HRESULT WINAPI DllCanUnloadNow(void)
285 return S_FALSE;
289 /*******************************************************************************
290 * DllGetClassObject [DDRAWEX.@]
292 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
294 IClassFactoryImpl *factory;
296 TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
298 if (!IsEqualGUID( &IID_IClassFactory, riid)
299 && !IsEqualGUID( &IID_IUnknown, riid))
300 return E_NOINTERFACE;
302 if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
304 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
305 return CLASS_E_CLASSNOTAVAILABLE;
308 factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
309 if (factory == NULL) return E_OUTOFMEMORY;
311 factory->IClassFactory_iface.lpVtbl = &IClassFactory_Vtbl;
312 factory->ref = 1;
314 factory->pfnCreateInstance = CreateDirectDrawFactory;
316 *ppv = factory;
318 return S_OK;
322 /***********************************************************************
323 * DllMain
325 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
327 switch (reason)
329 case DLL_PROCESS_ATTACH:
330 instance = hInstDLL;
331 DisableThreadLibraryCalls( hInstDLL );
332 break;
334 return TRUE;
337 /***********************************************************************
338 * DllRegisterServer (DDRAWEX.@)
340 HRESULT WINAPI DllRegisterServer(void)
342 return __wine_register_resources( instance, NULL );
345 /***********************************************************************
346 * DllUnregisterServer (DDRAWEX.@)
348 HRESULT WINAPI DllUnregisterServer(void)
350 return __wine_unregister_resources( instance, NULL );