ws2_32: Accept NULL lpNumberOfBytesSent for overlapped calls to WSASend/To.
[wine] / dlls / dmstyle / dmstyle_main.c
1 /* DirectMusicStyle Main
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
5  * This program 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.
9  *
10  * This program 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.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "dmstyle_private.h"
21 #include "rpcproxy.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
24
25 static HINSTANCE instance;
26 LONG DMSTYLE_refCount = 0;
27
28 typedef struct {
29     const IClassFactoryVtbl *lpVtbl;
30 } IClassFactoryImpl;
31
32 /******************************************************************
33  *              DirectMusicSection ClassFactory
34  */
35 static HRESULT WINAPI SectionCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
36         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
37
38         if (ppobj == NULL) return E_POINTER;
39         
40         return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI SectionCF_AddRef(LPCLASSFACTORY iface) {
44         DMSTYLE_LockModule();
45
46         return 2; /* non-heap based object */
47 }
48
49 static ULONG WINAPI SectionCF_Release(LPCLASSFACTORY iface) {
50         DMSTYLE_UnlockModule();
51
52         return 1; /* non-heap based object */
53 }
54
55 static HRESULT WINAPI SectionCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
56         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
57
58         /* nothing here yet */
59         WARN("(%s, %p): not found\n", debugstr_dmguid(riid), ppobj);
60         
61         return E_NOINTERFACE;
62 }
63
64 static HRESULT WINAPI SectionCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
65         TRACE("(%d)\n", dolock);
66
67         if (dolock)
68                 DMSTYLE_LockModule();
69         else
70                 DMSTYLE_UnlockModule();
71
72         return S_OK;
73 }
74
75 static const IClassFactoryVtbl SectionCF_Vtbl = {
76         SectionCF_QueryInterface,
77         SectionCF_AddRef,
78         SectionCF_Release,
79         SectionCF_CreateInstance,
80         SectionCF_LockServer
81 };
82
83 static IClassFactoryImpl Section_CF = {&SectionCF_Vtbl};
84
85 /******************************************************************
86  *              DirectMusicStyle ClassFactory
87  */
88 static HRESULT WINAPI StyleCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
89         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
90
91         if (ppobj == NULL) return E_POINTER;
92         
93         return E_NOINTERFACE;
94 }
95
96 static ULONG WINAPI StyleCF_AddRef(LPCLASSFACTORY iface) {
97         DMSTYLE_LockModule();
98
99         return 2; /* non-heap based object */
100 }
101
102 static ULONG WINAPI StyleCF_Release(LPCLASSFACTORY iface) {
103         DMSTYLE_UnlockModule();
104
105         return 1; /* non-heap based object */
106 }
107
108 static HRESULT WINAPI StyleCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
109         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
110         
111         return DMUSIC_CreateDirectMusicStyleImpl (riid, ppobj, pOuter);
112 }
113
114 static HRESULT WINAPI StyleCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
115         TRACE("(%d)\n", dolock);
116
117         if (dolock)
118                 DMSTYLE_LockModule();
119         else
120                 DMSTYLE_UnlockModule();
121
122         return S_OK;
123 }
124
125 static const IClassFactoryVtbl StyleCF_Vtbl = {
126         StyleCF_QueryInterface,
127         StyleCF_AddRef,
128         StyleCF_Release,
129         StyleCF_CreateInstance,
130         StyleCF_LockServer
131 };
132
133 static IClassFactoryImpl Style_CF = {&StyleCF_Vtbl};
134
135 /******************************************************************
136  *              DirectMusicChordTrack ClassFactory
137  */
138 static HRESULT WINAPI ChordTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
139         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
140
141         if (ppobj == NULL) return E_POINTER;
142         
143         return E_NOINTERFACE;
144 }
145
146 static ULONG WINAPI ChordTrackCF_AddRef(LPCLASSFACTORY iface) {
147         DMSTYLE_LockModule();
148
149         return 2; /* non-heap based object */
150 }
151
152 static ULONG WINAPI ChordTrackCF_Release(LPCLASSFACTORY iface) {
153         DMSTYLE_UnlockModule();
154
155         return 1; /* non-heap based object */
156 }
157
158 static HRESULT WINAPI ChordTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
159         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
160
161         return DMUSIC_CreateDirectMusicChordTrack (riid, ppobj, pOuter);
162 }
163
164 static HRESULT WINAPI ChordTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
165         TRACE("(%d)\n", dolock);
166
167         if (dolock)
168                 DMSTYLE_LockModule();
169         else
170                 DMSTYLE_UnlockModule();
171         
172         return S_OK;
173 }
174
175 static const IClassFactoryVtbl ChordTrackCF_Vtbl = {
176         ChordTrackCF_QueryInterface,
177         ChordTrackCF_AddRef,
178         ChordTrackCF_Release,
179         ChordTrackCF_CreateInstance,
180         ChordTrackCF_LockServer
181 };
182
183 static IClassFactoryImpl ChordTrack_CF = {&ChordTrackCF_Vtbl};
184
185 /******************************************************************
186  *              DirectMusicCommandTrack ClassFactory
187  */
188 static HRESULT WINAPI CommandTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
189         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
190
191         if (ppobj == NULL) return E_POINTER;
192         
193         return E_NOINTERFACE;
194 }
195
196 static ULONG WINAPI CommandTrackCF_AddRef(LPCLASSFACTORY iface) {
197         DMSTYLE_LockModule();
198
199         return 2; /* non-heap based object */
200 }
201
202 static ULONG WINAPI CommandTrackCF_Release(LPCLASSFACTORY iface) {
203         DMSTYLE_UnlockModule();
204
205         return 1; /* non-heap based object */
206 }
207
208 static HRESULT WINAPI CommandTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
209         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
210
211         return DMUSIC_CreateDirectMusicCommandTrack (riid, ppobj, pOuter);
212 }
213
214 static HRESULT WINAPI CommandTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
215         TRACE("(%d)\n", dolock);
216
217         if (dolock)
218                 DMSTYLE_LockModule();
219         else
220                 DMSTYLE_UnlockModule();
221         
222         return S_OK;
223 }
224
225 static const IClassFactoryVtbl CommandTrackCF_Vtbl = {
226         CommandTrackCF_QueryInterface,
227         CommandTrackCF_AddRef,
228         CommandTrackCF_Release,
229         CommandTrackCF_CreateInstance,
230         CommandTrackCF_LockServer
231 };
232
233 static IClassFactoryImpl CommandTrack_CF = {&CommandTrackCF_Vtbl};
234
235 /******************************************************************
236  *              DirectMusicStyleTrack ClassFactory
237  */
238 static HRESULT WINAPI StyleTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
239         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
240
241         if (ppobj == NULL) return E_POINTER;
242         
243         return E_NOINTERFACE;
244 }
245
246 static ULONG WINAPI StyleTrackCF_AddRef(LPCLASSFACTORY iface) {
247         DMSTYLE_LockModule();
248
249         return 2; /* non-heap based object */
250 }
251
252 static ULONG WINAPI StyleTrackCF_Release(LPCLASSFACTORY iface) {
253         DMSTYLE_UnlockModule();
254
255         return 1; /* non-heap based object */
256 }
257
258 static HRESULT WINAPI StyleTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
259         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
260         
261         return DMUSIC_CreateDirectMusicStyleTrack (riid, ppobj, pOuter);
262 }
263
264 static HRESULT WINAPI StyleTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
265         TRACE("(%d)\n", dolock);
266
267         if (dolock)
268                 DMSTYLE_LockModule();
269         else
270                 DMSTYLE_UnlockModule();
271         
272         return S_OK;
273 }
274
275 static const IClassFactoryVtbl StyleTrackCF_Vtbl = {
276         StyleTrackCF_QueryInterface,
277         StyleTrackCF_AddRef,
278         StyleTrackCF_Release,
279         StyleTrackCF_CreateInstance,
280         StyleTrackCF_LockServer
281 };
282
283 static IClassFactoryImpl StyleTrack_CF = {&StyleTrackCF_Vtbl};
284
285 /******************************************************************
286  *              DirectMusicMotifTrack ClassFactory
287  */
288 static HRESULT WINAPI MotifTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
289         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
290
291         if (ppobj == NULL) return E_POINTER;
292         
293         return E_NOINTERFACE;
294 }
295
296 static ULONG WINAPI MotifTrackCF_AddRef(LPCLASSFACTORY iface) {
297         DMSTYLE_LockModule();
298
299         return 2; /* non-heap based object */
300 }
301
302 static ULONG WINAPI MotifTrackCF_Release(LPCLASSFACTORY iface) {
303         DMSTYLE_UnlockModule();
304
305         return 1; /* non-heap based object */
306 }
307
308 static HRESULT WINAPI MotifTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
309         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
310         
311         return DMUSIC_CreateDirectMusicMotifTrack (riid, ppobj, pOuter);
312 }
313
314 static HRESULT WINAPI MotifTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
315         TRACE("(%d)\n", dolock);
316
317         if (dolock)
318                 DMSTYLE_LockModule();
319         else
320                 DMSTYLE_UnlockModule();
321         
322         return S_OK;
323 }
324
325 static const IClassFactoryVtbl MotifTrackCF_Vtbl = {
326         MotifTrackCF_QueryInterface,
327         MotifTrackCF_AddRef,
328         MotifTrackCF_Release,
329         MotifTrackCF_CreateInstance,
330         MotifTrackCF_LockServer
331 };
332
333 static IClassFactoryImpl MotifTrack_CF = {&MotifTrackCF_Vtbl};
334
335 /******************************************************************
336  *              DirectMusicAuditionTrack ClassFactory
337  */
338 static HRESULT WINAPI AuditionTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
339         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
340
341         if (ppobj == NULL) return E_POINTER;
342         
343         return E_NOINTERFACE;
344 }
345
346 static ULONG WINAPI AuditionTrackCF_AddRef(LPCLASSFACTORY iface) {
347         DMSTYLE_LockModule();
348
349         return 2; /* non-heap based object */
350 }
351
352 static ULONG WINAPI AuditionTrackCF_Release(LPCLASSFACTORY iface) {
353         DMSTYLE_UnlockModule();
354
355         return 1; /* non-heap based object */
356 }
357
358 static HRESULT WINAPI AuditionTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
359         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
360         
361         return DMUSIC_CreateDirectMusicAuditionTrack (riid, ppobj, pOuter);
362 }
363
364 static HRESULT WINAPI AuditionTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
365         TRACE("(%d)\n", dolock);
366
367         if (dolock)
368                 DMSTYLE_LockModule();
369         else
370                 DMSTYLE_UnlockModule();
371
372         return S_OK;
373 }
374
375 static const IClassFactoryVtbl AuditionTrackCF_Vtbl = {
376         AuditionTrackCF_QueryInterface,
377         AuditionTrackCF_AddRef,
378         AuditionTrackCF_Release,
379         AuditionTrackCF_CreateInstance,
380         AuditionTrackCF_LockServer
381 };
382
383 static IClassFactoryImpl AuditionTrack_CF = {&AuditionTrackCF_Vtbl};
384
385 /******************************************************************
386  *              DirectMusicMuteTrack ClassFactory
387  */
388 static HRESULT WINAPI MuteTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
389         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
390
391         if (ppobj == NULL) return E_POINTER;
392         
393         return E_NOINTERFACE;
394 }
395
396 static ULONG WINAPI MuteTrackCF_AddRef(LPCLASSFACTORY iface) {
397         DMSTYLE_LockModule();
398
399         return 2; /* non-heap based object */
400 }
401
402 static ULONG WINAPI MuteTrackCF_Release(LPCLASSFACTORY iface) {
403         DMSTYLE_UnlockModule();
404
405         return 1; /* non-heap based object */
406 }
407
408 static HRESULT WINAPI MuteTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
409         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
410
411         return DMUSIC_CreateDirectMusicMuteTrack (riid, ppobj, pOuter);
412 }
413
414 static HRESULT WINAPI MuteTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
415         TRACE("(%d)\n", dolock);
416
417         if (dolock)
418                 DMSTYLE_LockModule();
419         else
420                 DMSTYLE_UnlockModule();
421         
422         return S_OK;
423 }
424
425 static const IClassFactoryVtbl MuteTrackCF_Vtbl = {
426         MuteTrackCF_QueryInterface,
427         MuteTrackCF_AddRef,
428         MuteTrackCF_Release,
429         MuteTrackCF_CreateInstance,
430         MuteTrackCF_LockServer
431 };
432
433 static IClassFactoryImpl MuteTrack_CF = {&MuteTrackCF_Vtbl};
434
435 /******************************************************************
436  *              DllMain
437  *
438  *
439  */
440 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
441         if (fdwReason == DLL_PROCESS_ATTACH) {
442             instance = hinstDLL;
443             DisableThreadLibraryCalls(hinstDLL);
444                 /* FIXME: Initialisation */
445         } else if (fdwReason == DLL_PROCESS_DETACH) {
446                 /* FIXME: Cleanup */
447         }
448
449         return TRUE;
450 }
451
452
453 /******************************************************************
454  *              DllCanUnloadNow (DMSTYLE.1)
455  *
456  *
457  */
458 HRESULT WINAPI DllCanUnloadNow(void) {
459         return DMSTYLE_refCount != 0 ? S_FALSE : S_OK;
460 }
461
462
463 /******************************************************************
464  *              DllGetClassObject (DMSTYLE.@)
465  *
466  *
467  */
468 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
469     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
470     
471         if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSection) && IsEqualIID (riid, &IID_IClassFactory)) {
472                 *ppv = &Section_CF;
473                 IClassFactory_AddRef((IClassFactory*)*ppv);
474                 return S_OK;
475         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicStyle) && IsEqualIID (riid, &IID_IClassFactory)) {
476                 *ppv = &Style_CF;
477                 IClassFactory_AddRef((IClassFactory*)*ppv);
478                 return S_OK;            
479         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
480                 *ppv = &ChordTrack_CF;
481                 IClassFactory_AddRef((IClassFactory*)*ppv);
482                 return S_OK;    
483         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCommandTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
484                 *ppv = &CommandTrack_CF;
485                 IClassFactory_AddRef((IClassFactory*)*ppv);
486                 return S_OK;            
487         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicStyleTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
488                 *ppv = &StyleTrack_CF;
489                 IClassFactory_AddRef((IClassFactory*)*ppv);
490                 return S_OK;            
491         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMotifTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
492                 *ppv = &MotifTrack_CF;
493                 IClassFactory_AddRef((IClassFactory*)*ppv);
494                 return S_OK;            
495         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicAuditionTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
496                 *ppv = &AuditionTrack_CF;
497                 IClassFactory_AddRef((IClassFactory*)*ppv);
498                 return S_OK;            
499         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMuteTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
500                 *ppv = &MuteTrack_CF;
501                 IClassFactory_AddRef((IClassFactory*)*ppv);
502                 return S_OK;            
503         }
504
505     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
506     return CLASS_E_CLASSNOTAVAILABLE;
507 }
508
509 /***********************************************************************
510  *              DllRegisterServer (DMSTYLE.@)
511  */
512 HRESULT WINAPI DllRegisterServer(void)
513 {
514     return __wine_register_resources( instance, NULL );
515 }
516
517 /***********************************************************************
518  *              DllUnregisterServer (DMSTYLE.@)
519  */
520 HRESULT WINAPI DllUnregisterServer(void)
521 {
522     return __wine_unregister_resources( instance, NULL );
523 }