wined3d: Get rid of the IWineD3DStateBlockImpl typedef.
[wine] / dlls / dmband / dmband_main.c
1 /* DirectMusicBand 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 "dmband_private.h"
21 #include "rpcproxy.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmband);
24
25 static HINSTANCE instance;
26 LONG DMBAND_refCount = 0;
27
28 typedef struct {
29     const IClassFactoryVtbl *lpVtbl;
30 } IClassFactoryImpl;
31
32 /******************************************************************
33  *              DirectMusicBand ClassFactory
34  */
35  
36 static HRESULT WINAPI BandCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
37         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
38
39         if (ppobj == NULL) return E_POINTER;
40
41         return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI BandCF_AddRef(LPCLASSFACTORY iface) {
45         DMBAND_LockModule();
46
47         return 2; /* non-heap based object */
48 }
49
50 static ULONG WINAPI BandCF_Release(LPCLASSFACTORY iface) {
51         DMBAND_UnlockModule();
52
53         return 1; /* non-heap based object */
54 }
55
56 static HRESULT WINAPI BandCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
57         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
58         
59         return DMUSIC_CreateDirectMusicBandImpl (riid, ppobj, pOuter);
60 }
61
62 static HRESULT WINAPI BandCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
63         TRACE("(%d)\n", dolock);
64
65         if (dolock)
66                 DMBAND_LockModule();
67         else
68                 DMBAND_UnlockModule();
69         
70         return S_OK;
71 }
72
73 static const IClassFactoryVtbl BandCF_Vtbl = {
74         BandCF_QueryInterface,
75         BandCF_AddRef,
76         BandCF_Release,
77         BandCF_CreateInstance,
78         BandCF_LockServer
79 };
80
81 static IClassFactoryImpl Band_CF = {&BandCF_Vtbl};
82
83
84 /******************************************************************
85  *              DirectMusicBandTrack ClassFactory
86  */
87  
88 static HRESULT WINAPI BandTrackCF_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 BandTrackCF_AddRef(LPCLASSFACTORY iface) {
97         DMBAND_LockModule();
98
99         return 2; /* non-heap based object */
100 }
101
102 static ULONG WINAPI BandTrackCF_Release(LPCLASSFACTORY iface) {
103         DMBAND_UnlockModule();
104
105         return 1; /* non-heap based object */
106 }
107
108 static HRESULT WINAPI BandTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
109         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
110         
111         return DMUSIC_CreateDirectMusicBandTrack (riid, ppobj, pOuter);
112 }
113
114 static HRESULT WINAPI BandTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
115         TRACE("(%d)\n", dolock);
116
117         if (dolock)
118                 DMBAND_LockModule();
119         else
120                 DMBAND_UnlockModule();
121         
122         return S_OK;
123 }
124
125 static const IClassFactoryVtbl BandTrackCF_Vtbl = {
126         BandTrackCF_QueryInterface,
127         BandTrackCF_AddRef,
128         BandTrackCF_Release,
129         BandTrackCF_CreateInstance,
130         BandTrackCF_LockServer
131 };
132
133 static IClassFactoryImpl BandTrack_CF = {&BandTrackCF_Vtbl};
134
135 /******************************************************************
136  *              DllMain
137  *
138  *
139  */
140 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
141         if (fdwReason == DLL_PROCESS_ATTACH) {
142             instance = hinstDLL;
143             DisableThreadLibraryCalls(hinstDLL);
144                 /* FIXME: Initialisation */
145         } else if (fdwReason == DLL_PROCESS_DETACH) {
146                 /* FIXME: Cleanup */
147         }
148
149         return TRUE;
150 }
151
152
153 /******************************************************************
154  *              DllCanUnloadNow (DMBAND.@)
155  *
156  *
157  */
158 HRESULT WINAPI DllCanUnloadNow(void)
159 {
160         return DMBAND_refCount != 0 ? S_FALSE : S_OK;
161 }
162
163
164 /******************************************************************
165  *              DllGetClassObject (DMBAND.@)
166  *
167  *
168  */
169 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
170 {
171     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
172
173         if (IsEqualCLSID (rclsid, &CLSID_DirectMusicBand) && IsEqualIID (riid, &IID_IClassFactory)) {
174                 *ppv = &Band_CF;
175                 IClassFactory_AddRef((IClassFactory*)*ppv);
176                 return S_OK;
177         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicBandTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
178                 *ppv = &BandTrack_CF;
179                 IClassFactory_AddRef((IClassFactory*)*ppv);
180                 return S_OK;    
181         }
182         
183     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
184     return CLASS_E_CLASSNOTAVAILABLE;
185 }
186
187 /***********************************************************************
188  *              DllRegisterServer (DMBAND.@)
189  */
190 HRESULT WINAPI DllRegisterServer(void)
191 {
192     return __wine_register_resources( instance, NULL );
193 }
194
195 /***********************************************************************
196  *              DllUnregisterServer (DMBAND.@)
197  */
198 HRESULT WINAPI DllUnregisterServer(void)
199 {
200     return __wine_unregister_resources( instance, NULL );
201 }