credui: Add a banner and message box to the dialog presented by CredUIPromptForCreden...
[wine] / dlls / quartz / main.c
1 /*              DirectShow Base Functions (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  *
5  * This file contains the (internal) driver registration functions,
6  * driver enumeration APIs and DirectDraw creation functions.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "wine/debug.h"
25
26 #include "quartz_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29
30 static DWORD dll_ref = 0;
31
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
34 {
35     switch(fdwReason) {
36         case DLL_PROCESS_ATTACH:
37             DisableThreadLibraryCalls(hInstDLL);
38             break;
39         case DLL_PROCESS_DETACH:
40             break;
41     }
42     return TRUE;
43 }
44
45 /******************************************************************************
46  * DirectShow ClassFactory
47  */
48 typedef struct {
49     IClassFactory ITF_IClassFactory;
50
51     LONG ref;
52     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 } IClassFactoryImpl;
54
55 struct object_creation_info
56 {
57     const CLSID *clsid;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 };
60
61 static const struct object_creation_info object_creation[] =
62 {
63     { &CLSID_FilterGraph, FilterGraph_create },
64     { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
65     { &CLSID_FilterMapper, FilterMapper_create },
66     { &CLSID_FilterMapper2, FilterMapper2_create },
67     { &CLSID_AsyncReader, AsyncReader_create },
68     { &CLSID_MemoryAllocator, StdMemAllocator_create },
69     { &CLSID_AviSplitter, AVISplitter_create },
70     { &CLSID_MPEG1Splitter, MPEGSplitter_create },
71     { &CLSID_VideoRenderer, VideoRenderer_create },
72     { &CLSID_DSoundRender, DSoundRender_create },
73     { &CLSID_AVIDec, AVIDec_create },
74     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
75     { &CLSID_ACMWrapper, &ACMWrapper_create },
76     { &CLSID_WAVEParser, &WAVEParser_create }
77 };
78
79 static HRESULT WINAPI
80 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
81 {
82     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
83
84     if (IsEqualGUID(riid, &IID_IUnknown)
85         || IsEqualGUID(riid, &IID_IClassFactory))
86     {
87         IClassFactory_AddRef(iface);
88         *ppobj = This;
89         return S_OK;
90     }
91
92     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
93     return E_NOINTERFACE;
94 }
95
96 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
97 {
98     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
99     return InterlockedIncrement(&This->ref);
100 }
101
102 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
103 {
104     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
105
106     ULONG ref = InterlockedDecrement(&This->ref);
107
108     if (ref == 0)
109         CoTaskMemFree(This);
110
111     return ref;
112 }
113
114
115 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
116                                           REFIID riid, LPVOID *ppobj)
117 {
118     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
119     HRESULT hres;
120     LPUNKNOWN punk;
121     
122     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
123
124     *ppobj = NULL;
125     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
126     if (SUCCEEDED(hres)) {
127         hres = IUnknown_QueryInterface(punk, riid, ppobj);
128         IUnknown_Release(punk);
129     }
130     return hres;
131 }
132
133 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
134 {
135     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
136     FIXME("(%p)->(%d),stub!\n",This,dolock);
137     return S_OK;
138 }
139
140 static const IClassFactoryVtbl DSCF_Vtbl =
141 {
142     DSCF_QueryInterface,
143     DSCF_AddRef,
144     DSCF_Release,
145     DSCF_CreateInstance,
146     DSCF_LockServer
147 };
148
149 /*******************************************************************************
150  * DllGetClassObject [QUARTZ.@]
151  * Retrieves class object from a DLL object
152  *
153  * NOTES
154  *    Docs say returns STDAPI
155  *
156  * PARAMS
157  *    rclsid [I] CLSID for the class object
158  *    riid   [I] Reference to identifier of interface for class object
159  *    ppv    [O] Address of variable to receive interface pointer for riid
160  *
161  * RETURNS
162  *    Success: S_OK
163  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
164  *             E_UNEXPECTED
165  */
166 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
167 {
168     unsigned int i;
169     IClassFactoryImpl *factory;
170     
171     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
172     
173     if ( !IsEqualGUID( &IID_IClassFactory, riid )
174          && ! IsEqualGUID( &IID_IUnknown, riid) )
175         return E_NOINTERFACE;
176
177     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
178     {
179         if (IsEqualGUID(object_creation[i].clsid, rclsid))
180             break;
181     }
182
183     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
184     {
185         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
186         return CLASS_E_CLASSNOTAVAILABLE;
187     }
188
189     factory = CoTaskMemAlloc(sizeof(*factory));
190     if (factory == NULL) return E_OUTOFMEMORY;
191
192     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
193     factory->ref = 1;
194
195     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
196
197     *ppv = &(factory->ITF_IClassFactory);
198     return S_OK;
199 }
200
201 /***********************************************************************
202  *              DllCanUnloadNow (QUARTZ.@)
203  */
204 HRESULT WINAPI DllCanUnloadNow(void)
205 {
206     return dll_ref != 0 ? S_FALSE : S_OK;
207 }
208
209
210 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
211     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
212
213 static const struct {
214         const GUID      riid;
215         const char      *name;
216 } InterfaceDesc[] =
217 {
218 #include "uuids.h"
219     { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
220 };
221
222 /***********************************************************************
223  *              qzdebugstr_guid (internal)
224  *
225  * Gives a text version of DirectShow GUIDs
226  */
227 const char * qzdebugstr_guid( const GUID * id )
228 {
229     int i;
230     char * name = NULL;
231
232     for (i=0;InterfaceDesc[i].name && !name;i++) {
233         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
234     }
235     return debugstr_guid(id);
236 }
237
238 /***********************************************************************
239  *              qzdebugstr_State (internal)
240  *
241  * Gives a text version of the FILTER_STATE enumeration
242  */
243 const char * qzdebugstr_State(FILTER_STATE state)
244 {
245     switch (state)
246     {
247     case State_Stopped:
248         return "State_Stopped";
249     case State_Running:
250         return "State_Running";
251     case State_Paused:
252         return "State_Paused";
253     default:
254         return "State_Unknown";
255     }
256 }
257
258 LONG WINAPI AmpFactorToDB(LONG ampfactor)
259 {
260     FIXME("(%d) Stub!\n", ampfactor);
261     return 0;
262 }
263
264 LONG WINAPI DBToAmpFactor(LONG db)
265 {
266     FIXME("(%d) Stub!\n", db);
267     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
268     if (db < -1000)
269         return 0;
270     return 100;
271 }
272
273 /***********************************************************************
274  *              AMGetErrorTextA (QUARTZ.@)
275  */
276 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
277 {
278     int len;
279     static const char format[] = "Error: 0x%x";
280     char error[MAX_ERROR_TEXT_LEN];
281
282     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
283
284     if (!buffer) return 0;
285     wsprintfA(error, format, hr);
286     if ((len = lstrlenA(error)) >= maxlen) return 0; 
287     lstrcpyA(buffer, error);
288     return len;
289 }
290
291 /***********************************************************************
292  *              AMGetErrorTextW (QUARTZ.@)
293  */
294 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
295 {
296     int len;
297     static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
298     WCHAR error[MAX_ERROR_TEXT_LEN];
299
300     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
301
302     if (!buffer) return 0;
303     wsprintfW(error, format, hr);
304     if ((len = lstrlenW(error)) >= maxlen) return 0; 
305     lstrcpyW(buffer, error);
306     return len;
307 }