oleaut32: Fixed setting oVft value in ITypeInfo2::GetFuncDesc.
[wine] / dlls / dmime / dmime_main.c
1 /* DirectMusicInteractiveEngine Main
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  * Copyright (C) 2003-2004 Raphael Junqueira
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "dmime_private.h"
22 #include "rpcproxy.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
25
26 static HINSTANCE instance;
27 LONG DMIME_refCount = 0;
28
29 typedef struct {
30         IClassFactory IClassFactory_iface;
31         HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
32 } IClassFactoryImpl;
33
34 /******************************************************************
35  *      IClassFactory implementation
36  */
37 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
38 {
39         return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
40 }
41
42 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
43 {
44         if (ppv == NULL)
45                 return E_POINTER;
46
47         if (IsEqualGUID(&IID_IUnknown, riid))
48                 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
49         else if (IsEqualGUID(&IID_IClassFactory, riid))
50                 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
51         else {
52                 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
53                 *ppv = NULL;
54                 return E_NOINTERFACE;
55         }
56
57         *ppv = iface;
58         IUnknown_AddRef((IUnknown*)*ppv);
59         return S_OK;
60 }
61
62 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
63 {
64         DMIME_LockModule();
65
66         return 2; /* non-heap based object */
67 }
68
69 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
70 {
71         DMIME_UnlockModule();
72
73         return 1; /* non-heap based object */
74 }
75
76 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
77         REFIID riid, void **ppv)
78 {
79         IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80
81         TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
82
83         return This->fnCreateInstance(riid, ppv, pUnkOuter);
84 }
85
86 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
87 {
88         TRACE("(%d)\n", dolock);
89
90         if (dolock)
91                 DMIME_LockModule();
92         else
93                 DMIME_UnlockModule();
94
95         return S_OK;
96 }
97
98 static const IClassFactoryVtbl classfactory_vtbl = {
99         ClassFactory_QueryInterface,
100         ClassFactory_AddRef,
101         ClassFactory_Release,
102         ClassFactory_CreateInstance,
103         ClassFactory_LockServer
104 };
105
106
107 static IClassFactoryImpl Performance_CF = {{&classfactory_vtbl},
108                                            DMUSIC_CreateDirectMusicPerformanceImpl};
109 static IClassFactoryImpl Segment_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSegmentImpl};
110 static IClassFactoryImpl SegmentState_CF = {{&classfactory_vtbl},
111                                             DMUSIC_CreateDirectMusicSegmentStateImpl};
112 static IClassFactoryImpl Graph_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicGraphImpl};
113 static IClassFactoryImpl TempoTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicTempoTrack};
114 static IClassFactoryImpl SeqTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSeqTrack};
115 static IClassFactoryImpl SysExTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSysExTrack};
116 static IClassFactoryImpl TimeSigTrack_CF = {{&classfactory_vtbl},
117                                             DMUSIC_CreateDirectMusicTimeSigTrack};
118 static IClassFactoryImpl ParamControlTrack_CF = {{&classfactory_vtbl},
119                                                  DMUSIC_CreateDirectMusicParamControlTrack};
120 static IClassFactoryImpl MarkerTrack_CF = {{&classfactory_vtbl},
121                                            DMUSIC_CreateDirectMusicMarkerTrack};
122 static IClassFactoryImpl LyricsTrack_CF = {{&classfactory_vtbl},
123                                            DMUSIC_CreateDirectMusicLyricsTrack};
124 static IClassFactoryImpl SegTriggerTrack_CF = {{&classfactory_vtbl},
125                                                DMUSIC_CreateDirectMusicSegTriggerTrack};
126 static IClassFactoryImpl AudioPath_CF = {{&classfactory_vtbl},
127                                          DMUSIC_CreateDirectMusicAudioPathImpl};
128 static IClassFactoryImpl WaveTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicWaveTrack};
129
130 /******************************************************************
131  *              DllMain
132  *
133  *
134  */
135 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
136         if (fdwReason == DLL_PROCESS_ATTACH) {
137                 instance = hinstDLL;
138                 DisableThreadLibraryCalls(hinstDLL);
139                 /* FIXME: Initialisation */
140         }
141         else if (fdwReason == DLL_PROCESS_DETACH) {
142                 /* FIXME: Cleanup */
143         }
144
145         return TRUE;
146 }
147
148
149 /******************************************************************
150  *              DllCanUnloadNow (DMIME.1)
151  *
152  *
153  */
154 HRESULT WINAPI DllCanUnloadNow(void)
155 {
156         return DMIME_refCount != 0 ? S_FALSE : S_OK;
157 }
158
159
160 /******************************************************************
161  *              DllGetClassObject (DMIME.@)
162  *
163  *
164  */
165 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
166 {
167     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
168     if (IsEqualCLSID (rclsid, &CLSID_DirectMusicPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
169                 *ppv = &Performance_CF;
170                 IClassFactory_AddRef((IClassFactory*)*ppv);
171                 return S_OK;
172         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
173                 *ppv = &Segment_CF;
174                 IClassFactory_AddRef((IClassFactory*)*ppv);
175                 return S_OK;
176         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
177                 *ppv = &SegmentState_CF;
178                 IClassFactory_AddRef((IClassFactory*)*ppv);
179                 return S_OK;
180         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicGraph) && IsEqualIID (riid, &IID_IClassFactory)) {
181                 *ppv = &Graph_CF;
182                 IClassFactory_AddRef((IClassFactory*)*ppv);
183                 return S_OK;
184         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTempoTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
185                 *ppv = &TempoTrack_CF;
186                 IClassFactory_AddRef((IClassFactory*)*ppv);
187                 return S_OK;
188         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSeqTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
189                 *ppv = &SeqTrack_CF;
190                 IClassFactory_AddRef((IClassFactory*)*ppv);
191                 return S_OK;
192         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSysExTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
193                 *ppv = &SysExTrack_CF;
194                 IClassFactory_AddRef((IClassFactory*)*ppv);
195                 return S_OK;
196         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTimeSigTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
197                 *ppv = &TimeSigTrack_CF;
198                 IClassFactory_AddRef((IClassFactory*)*ppv);
199                 return S_OK;
200         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicParamControlTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
201                 *ppv = &ParamControlTrack_CF;
202                 IClassFactory_AddRef((IClassFactory*)*ppv);
203                 return S_OK;
204         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMarkerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
205                 *ppv = &MarkerTrack_CF;
206                 IClassFactory_AddRef((IClassFactory*)*ppv);
207                 return S_OK;
208         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLyricsTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
209                 *ppv = &LyricsTrack_CF;
210                 IClassFactory_AddRef((IClassFactory*)*ppv);
211                 return S_OK;
212         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegTriggerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
213                 *ppv = &SegTriggerTrack_CF;
214                 IClassFactory_AddRef((IClassFactory*)*ppv);
215                 return S_OK;
216         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
217                 *ppv = &AudioPath_CF;
218                 IClassFactory_AddRef((IClassFactory*)*ppv);
219                 return S_OK;
220         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicWaveTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
221                 *ppv = &WaveTrack_CF;
222                 IClassFactory_AddRef((IClassFactory*)*ppv);
223                 return S_OK;
224         } 
225         
226     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
227     return CLASS_E_CLASSNOTAVAILABLE;
228 }
229
230 /***********************************************************************
231  *              DllRegisterServer (DMIME.@)
232  */
233 HRESULT WINAPI DllRegisterServer(void)
234 {
235     return __wine_register_resources( instance );
236 }
237
238 /***********************************************************************
239  *              DllUnregisterServer (DMIME.@)
240  */
241 HRESULT WINAPI DllUnregisterServer(void)
242 {
243     return __wine_unregister_resources( instance );
244 }