wined3d: Handle stateblock capture for default lights created while recording.
[wine] / dlls / mmdevapi / main.c
1 /*
2  * Copyright 2009 Maarten Lankhorst
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define CINTERFACE
24 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/debug.h"
28
29 #include "initguid.h"
30 #include "ole2.h"
31 #include "mmdeviceapi.h"
32
33 #include "mmdevapi.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
36
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
38 {
39     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
40
41     switch (fdwReason)
42     {
43         case DLL_PROCESS_ATTACH:
44             DisableThreadLibraryCalls(hinstDLL);
45             break;
46         case DLL_PROCESS_DETACH:
47             MMDevEnum_Free();
48             break;
49     }
50
51     return TRUE;
52 }
53
54 HRESULT WINAPI DllCanUnloadNow(void)
55 {
56     FIXME("stub\n");
57     return S_FALSE;
58 }
59
60 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
61
62 typedef struct {
63     const IClassFactoryVtbl *lpVtbl;
64     REFCLSID rclsid;
65     FnCreateInstance pfnCreateInstance;
66 } IClassFactoryImpl;
67
68 static HRESULT WINAPI
69 MMCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
70 {
71     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
72     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
73     if (ppobj == NULL)
74         return E_POINTER;
75     if (IsEqualIID(riid, &IID_IUnknown) ||
76         IsEqualIID(riid, &IID_IClassFactory))
77     {
78         *ppobj = iface;
79         IUnknown_AddRef(iface);
80         return S_OK;
81     }
82     *ppobj = NULL;
83     return E_NOINTERFACE;
84 }
85
86 static ULONG WINAPI MMCF_AddRef(LPCLASSFACTORY iface)
87 {
88     return 2;
89 }
90
91 static ULONG WINAPI MMCF_Release(LPCLASSFACTORY iface)
92 {
93     /* static class, won't be freed */
94     return 1;
95 }
96
97 static HRESULT WINAPI MMCF_CreateInstance(
98     LPCLASSFACTORY iface,
99     LPUNKNOWN pOuter,
100     REFIID riid,
101     LPVOID *ppobj)
102 {
103     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
104     TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
105
106     if (pOuter)
107         return CLASS_E_NOAGGREGATION;
108
109     if (ppobj == NULL) {
110         WARN("invalid parameter\n");
111         return E_POINTER;
112     }
113     *ppobj = NULL;
114     return This->pfnCreateInstance(riid, ppobj);
115 }
116
117 static HRESULT WINAPI MMCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
118 {
119     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
120     FIXME("(%p, %d) stub!\n", This, dolock);
121     return S_OK;
122 }
123
124 static const IClassFactoryVtbl MMCF_Vtbl = {
125     MMCF_QueryInterface,
126     MMCF_AddRef,
127     MMCF_Release,
128     MMCF_CreateInstance,
129     MMCF_LockServer
130 };
131
132 static IClassFactoryImpl MMDEVAPI_CF[] = {
133     { &MMCF_Vtbl, &CLSID_MMDeviceEnumerator, (FnCreateInstance)MMDevEnum_Create }
134 };
135
136 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
137 {
138     int i = 0;
139     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
140
141     if (ppv == NULL) {
142         WARN("invalid parameter\n");
143         return E_INVALIDARG;
144     }
145
146     *ppv = NULL;
147
148     if (!IsEqualIID(riid, &IID_IClassFactory) &&
149         !IsEqualIID(riid, &IID_IUnknown)) {
150         WARN("no interface for %s\n", debugstr_guid(riid));
151         return E_NOINTERFACE;
152     }
153
154     for (i = 0; i < sizeof(MMDEVAPI_CF)/sizeof(MMDEVAPI_CF[0]); ++i)
155     {
156         if (IsEqualGUID(rclsid, MMDEVAPI_CF[i].rclsid)) {
157             IUnknown_AddRef((IClassFactory*) &MMDEVAPI_CF[i]);
158             *ppv = &MMDEVAPI_CF[i];
159             return S_OK;
160         }
161         i++;
162     }
163
164     WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
165          debugstr_guid(riid), ppv);
166     return CLASS_E_CLASSNOTAVAILABLE;
167 }