dmime_main.c 8.76 KB
Newer Older
1 2
/* DirectMusicInteractiveEngine Main
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 * Copyright (C) 2003-2004 Raphael Junqueira
5
 *
6 7 8 9
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10 11 12
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
15
 *
16 17 18
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 */

21 22 23 24 25 26 27 28 29 30 31
#include <stdarg.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winnt.h"
#include "wingdi.h"
#include "winuser.h"
#include "winreg.h"
#include "objbase.h"
32
#include "rpcproxy.h"
33 34 35 36
#include "initguid.h"
#include "dmusici.h"

#include "dmime_private.h"
37

38
WINE_DEFAULT_DEBUG_CHANNEL(dmime);
39

40
static HINSTANCE instance;
41 42
LONG DMIME_refCount = 0;

43
typedef struct {
44
        IClassFactory IClassFactory_iface;
45
        HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ret_iface);
46 47
} IClassFactoryImpl;

48
/******************************************************************
49
 *      IClassFactory implementation
50
 */
51 52 53
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
        return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 55
}

56 57 58 59
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
        if (ppv == NULL)
                return E_POINTER;
60

61 62 63 64 65 66 67 68 69
        if (IsEqualGUID(&IID_IUnknown, riid))
                TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
        else if (IsEqualGUID(&IID_IClassFactory, riid))
                TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
        else {
                FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
                *ppv = NULL;
                return E_NOINTERFACE;
        }
70

71 72 73
        *ppv = iface;
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
74 75
}

76 77 78
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
        DMIME_LockModule();
79

80
        return 2; /* non-heap based object */
81 82
}

83 84 85
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
        DMIME_UnlockModule();
86

87
        return 1; /* non-heap based object */
88 89
}

90 91 92 93
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
        REFIID riid, void **ppv)
{
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
94

95
        TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
96

97 98 99 100
        if(pUnkOuter)
            return CLASS_E_NOAGGREGATION;

        return This->fnCreateInstance(riid, ppv);
101 102
}

103 104 105
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
        TRACE("(%d)\n", dolock);
106

107 108 109 110
        if (dolock)
                DMIME_LockModule();
        else
                DMIME_UnlockModule();
111

112
        return S_OK;
113 114
}

115 116 117 118 119 120
static const IClassFactoryVtbl classfactory_vtbl = {
        ClassFactory_QueryInterface,
        ClassFactory_AddRef,
        ClassFactory_Release,
        ClassFactory_CreateInstance,
        ClassFactory_LockServer
121 122
};

123

124 125 126 127 128 129 130 131 132 133 134 135 136 137
static IClassFactoryImpl Performance_CF = {{&classfactory_vtbl}, create_dmperformance};
static IClassFactoryImpl Segment_CF = {{&classfactory_vtbl}, create_dmsegment};
static IClassFactoryImpl SegmentState_CF = {{&classfactory_vtbl}, create_dmsegmentstate};
static IClassFactoryImpl Graph_CF = {{&classfactory_vtbl}, create_dmgraph};
static IClassFactoryImpl TempoTrack_CF = {{&classfactory_vtbl}, create_dmtempotrack};
static IClassFactoryImpl SeqTrack_CF = {{&classfactory_vtbl}, create_dmseqtrack};
static IClassFactoryImpl SysExTrack_CF = {{&classfactory_vtbl}, create_dmsysextrack};
static IClassFactoryImpl TimeSigTrack_CF = {{&classfactory_vtbl}, create_dmtimesigtrack};
static IClassFactoryImpl ParamControlTrack_CF = {{&classfactory_vtbl}, create_dmparamcontroltrack};
static IClassFactoryImpl MarkerTrack_CF = {{&classfactory_vtbl}, create_dmmarkertrack};
static IClassFactoryImpl LyricsTrack_CF = {{&classfactory_vtbl}, create_dmlyricstrack};
static IClassFactoryImpl SegTriggerTrack_CF = {{&classfactory_vtbl}, create_dmsegtriggertrack};
static IClassFactoryImpl AudioPath_CF = {{&classfactory_vtbl}, create_dmaudiopath};
static IClassFactoryImpl WaveTrack_CF = {{&classfactory_vtbl}, create_dmwavetrack};
138 139 140 141 142 143

/******************************************************************
 *		DllMain
 *
 *
 */
144 145
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
	if (fdwReason == DLL_PROCESS_ATTACH) {
146
                instance = hinstDLL;
147
		DisableThreadLibraryCalls(hinstDLL);
148 149 150 151 152 153 154 155 156 157 158
	}

	return TRUE;
}


/******************************************************************
 *		DllCanUnloadNow (DMIME.1)
 *
 *
 */
159 160
HRESULT WINAPI DllCanUnloadNow(void)
{
161
	return DMIME_refCount != 0 ? S_FALSE : S_OK;
162 163 164 165
}


/******************************************************************
166
 *		DllGetClassObject (DMIME.@)
167 168 169
 *
 *
 */
170
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
171
{
172
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
173
    if (IsEqualCLSID (rclsid, &CLSID_DirectMusicPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
174
                *ppv = &Performance_CF;
175 176 177
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
178
                *ppv = &Segment_CF;
179 180 181
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
182
                *ppv = &SegmentState_CF;
183 184 185
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicGraph) && IsEqualIID (riid, &IID_IClassFactory)) {
186
                *ppv = &Graph_CF;
187 188 189
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTempoTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
190
                *ppv = &TempoTrack_CF;
191 192 193
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSeqTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
194
                *ppv = &SeqTrack_CF;
195 196 197
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSysExTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
198
                *ppv = &SysExTrack_CF;
199 200 201
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTimeSigTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
202
                *ppv = &TimeSigTrack_CF;
203 204 205
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicParamControlTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
206
                *ppv = &ParamControlTrack_CF;
207 208 209
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMarkerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
210
                *ppv = &MarkerTrack_CF;
211 212 213
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLyricsTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
214
                *ppv = &LyricsTrack_CF;
215 216 217
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegTriggerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
218
                *ppv = &SegTriggerTrack_CF;
219 220
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
221 222
        } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicAudioPathConfig) &&
                   IsEqualIID (riid, &IID_IClassFactory)) {
223
                *ppv = &AudioPath_CF;
224 225 226
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicWaveTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
227
                *ppv = &WaveTrack_CF;
228 229 230 231
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} 
	
232
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
233 234
    return CLASS_E_CLASSNOTAVAILABLE;
}
235 236 237 238 239 240

/***********************************************************************
 *		DllRegisterServer (DMIME.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
241
    return __wine_register_resources( instance );
242 243 244 245 246 247 248
}

/***********************************************************************
 *		DllUnregisterServer (DMIME.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
249
    return __wine_unregister_resources( instance );
250
}