gdi32: Change an ERR to a WARN for fonts with too-long names.
[wine/multimedia.git] / dlls / quartz / main.c
blobb45c55b04b57d71a840807a38b5396d082e2ba5d
1 /* DirectShow Base Functions (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
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
20 #include "config.h"
21 #include "wine/debug.h"
23 #include "quartz_private.h"
24 #include "wine/unicode.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
28 extern HRESULT WINAPI QUARTZ_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
29 extern HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
30 extern BOOL WINAPI QUARTZ_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
32 static DWORD dll_ref = 0;
34 /* For the moment, do nothing here. */
35 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
37 return QUARTZ_DllMain( hInstDLL, fdwReason, lpv );
40 static HRESULT SeekingPassThru_create(IUnknown *pUnkOuter, LPVOID *ppObj)
42 return PosPassThru_Construct(pUnkOuter,ppObj); /* from strmbase */
45 /******************************************************************************
46 * DirectShow ClassFactory
48 typedef struct {
49 IClassFactory IClassFactory_iface;
50 LONG ref;
51 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
52 } IClassFactoryImpl;
54 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
56 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
59 struct object_creation_info
61 const CLSID *clsid;
62 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
65 static const struct object_creation_info object_creation[] =
67 { &CLSID_SeekingPassThru, SeekingPassThru_create },
68 { &CLSID_FilterGraph, FilterGraph_create },
69 { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
70 { &CLSID_FilterMapper, FilterMapper_create },
71 { &CLSID_FilterMapper2, FilterMapper2_create },
72 { &CLSID_AsyncReader, AsyncReader_create },
73 { &CLSID_MemoryAllocator, StdMemAllocator_create },
74 { &CLSID_AviSplitter, AVISplitter_create },
75 { &CLSID_MPEG1Splitter, MPEGSplitter_create },
76 { &CLSID_VideoRenderer, VideoRenderer_create },
77 { &CLSID_NullRenderer, NullRenderer_create },
78 { &CLSID_VideoMixingRenderer, VMR7Impl_create },
79 { &CLSID_VideoMixingRenderer9, VMR9Impl_create },
80 { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
81 { &CLSID_DSoundRender, DSoundRender_create },
82 { &CLSID_AudioRender, DSoundRender_create },
83 { &CLSID_AVIDec, AVIDec_create },
84 { &CLSID_SystemClock, QUARTZ_CreateSystemClock },
85 { &CLSID_ACMWrapper, ACMWrapper_create },
86 { &CLSID_WAVEParser, WAVEParser_create }
89 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
91 if (IsEqualGUID(riid, &IID_IUnknown)
92 || IsEqualGUID(riid, &IID_IClassFactory))
94 IClassFactory_AddRef(iface);
95 *ppobj = iface;
96 return S_OK;
99 *ppobj = NULL;
100 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
101 return E_NOINTERFACE;
104 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
106 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
107 return InterlockedIncrement(&This->ref);
110 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
112 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
113 ULONG ref = InterlockedDecrement(&This->ref);
115 if (ref == 0)
116 CoTaskMemFree(This);
118 return ref;
122 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
123 REFIID riid, void **ppobj)
125 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
126 HRESULT hres;
127 LPUNKNOWN punk;
129 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
131 *ppobj = NULL;
132 if(pOuter && !IsEqualGUID(&IID_IUnknown, riid))
133 return E_NOINTERFACE;
135 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
136 if (SUCCEEDED(hres)) {
137 hres = IUnknown_QueryInterface(punk, riid, ppobj);
138 IUnknown_Release(punk);
140 return hres;
143 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
145 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
146 FIXME("(%p)->(%d),stub!\n",This,dolock);
147 return S_OK;
150 static const IClassFactoryVtbl DSCF_Vtbl =
152 DSCF_QueryInterface,
153 DSCF_AddRef,
154 DSCF_Release,
155 DSCF_CreateInstance,
156 DSCF_LockServer
159 /*******************************************************************************
160 * DllGetClassObject [QUARTZ.@]
161 * Retrieves class object from a DLL object
163 * NOTES
164 * Docs say returns STDAPI
166 * PARAMS
167 * rclsid [I] CLSID for the class object
168 * riid [I] Reference to identifier of interface for class object
169 * ppv [O] Address of variable to receive interface pointer for riid
171 * RETURNS
172 * Success: S_OK
173 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
174 * E_UNEXPECTED
176 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
178 unsigned int i;
180 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
182 if (IsEqualGUID( &IID_IClassFactory, riid ) || IsEqualGUID( &IID_IUnknown, riid))
184 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
186 if (IsEqualGUID(object_creation[i].clsid, rclsid))
188 IClassFactoryImpl *factory = CoTaskMemAlloc(sizeof(*factory));
189 if (factory == NULL) return E_OUTOFMEMORY;
191 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
192 factory->ref = 1;
194 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
196 *ppv = &factory->IClassFactory_iface;
197 return S_OK;
201 return QUARTZ_DllGetClassObject( rclsid, riid, ppv );
204 /***********************************************************************
205 * DllCanUnloadNow (QUARTZ.@)
207 HRESULT WINAPI DllCanUnloadNow(void)
209 if (dll_ref) return S_FALSE;
210 return QUARTZ_DllCanUnloadNow();
214 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
215 { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } , #name },
217 static const struct {
218 const GUID riid;
219 const char *name;
220 } InterfaceDesc[] =
222 #include "uuids.h"
223 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
226 /***********************************************************************
227 * proxies
229 HRESULT CALLBACK ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder *This,
230 const GUID *pCategory,
231 IBaseFilter *pf,
232 REFIID riid,
233 void **ppint )
235 return ICaptureGraphBuilder_RemoteFindInterface_Proxy( This, pCategory, pf,
236 riid, (IUnknown **)ppint );
239 HRESULT __RPC_STUB ICaptureGraphBuilder_FindInterface_Stub( ICaptureGraphBuilder *This,
240 const GUID *pCategory,
241 IBaseFilter *pf,
242 REFIID riid,
243 IUnknown **ppint )
245 return ICaptureGraphBuilder_FindInterface( This, pCategory, pf, riid, (void **)ppint );
248 HRESULT CALLBACK ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2 *This,
249 const GUID *pCategory,
250 const GUID *pType,
251 IBaseFilter *pf,
252 REFIID riid,
253 void **ppint )
255 return ICaptureGraphBuilder2_RemoteFindInterface_Proxy( This, pCategory, pType,
256 pf, riid, (IUnknown **)ppint );
259 HRESULT __RPC_STUB ICaptureGraphBuilder2_FindInterface_Stub( ICaptureGraphBuilder2 *This,
260 const GUID *pCategory,
261 const GUID *pType,
262 IBaseFilter *pf,
263 REFIID riid,
264 IUnknown **ppint )
266 return ICaptureGraphBuilder2_FindInterface( This, pCategory, pType, pf, riid, (void **)ppint );
269 /***********************************************************************
270 * qzdebugstr_guid (internal)
272 * Gives a text version of DirectShow GUIDs
274 const char * qzdebugstr_guid( const GUID * id )
276 int i;
278 for (i=0; InterfaceDesc[i].name; i++)
279 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
281 return debugstr_guid(id);
284 LONG WINAPI AmpFactorToDB(LONG ampfactor)
286 FIXME("(%d) Stub!\n", ampfactor);
287 return 0;
290 LONG WINAPI DBToAmpFactor(LONG db)
292 FIXME("(%d) Stub!\n", db);
293 /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
294 if (db < -1000)
295 return 0;
296 return 100;
299 /***********************************************************************
300 * AMGetErrorTextA (QUARTZ.@)
302 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
304 DWORD res;
305 WCHAR errorW[MAX_ERROR_TEXT_LEN];
307 TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
308 if (!buffer)
309 return 0;
311 res = AMGetErrorTextW(hr, errorW, sizeof(errorW)/sizeof(*errorW));
312 return WideCharToMultiByte(CP_ACP, 0, errorW, res, buffer, maxlen, 0, 0);
315 /***********************************************************************
316 * AMGetErrorTextW (QUARTZ.@)
318 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
320 unsigned int len;
321 static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
322 WCHAR error[MAX_ERROR_TEXT_LEN];
324 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
326 if (!buffer) return 0;
327 wsprintfW(error, format, hr);
328 if ((len = strlenW(error)) >= maxlen) return 0;
329 lstrcpyW(buffer, error);
330 return len;