dmstyle_main.c 7.19 KB
Newer Older
1 2
/* DirectMusicStyle Main
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 *
5 6 7 8
 * 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.
9 10 11
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
15 16 17
 * 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
18 19 20
 */

#include "dmstyle_private.h"
21
#include "rpcproxy.h"
22

23
WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
24

25
static HINSTANCE instance;
26 27
LONG DMSTYLE_refCount = 0;

28
typedef struct {
29 30
        IClassFactory IClassFactory_iface;
        HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
31 32
} IClassFactoryImpl;

33 34 35
static HRESULT WINAPI create_direct_music_section(REFIID riid, void **ppv, IUnknown *pUnkOuter)
{
        FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
36

37
        return E_NOINTERFACE;
38 39 40
}

/******************************************************************
41
 *      IClassFactory implementation
42
 */
43 44 45
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
        return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
46 47
}

48 49 50 51
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
        if (ppv == NULL)
                return E_POINTER;
52

53 54 55 56 57 58 59 60 61 62 63 64 65
        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;
        }

        *ppv = iface;
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
66 67
}

68 69 70
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
        DMSTYLE_LockModule();
71

72
        return 2; /* non-heap based object */
73 74
}

75 76 77
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
        DMSTYLE_UnlockModule();
78

79
        return 1; /* non-heap based object */
80 81
}

82 83 84 85
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
        REFIID riid, void **ppv)
{
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
86

87
        TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
88

89
        return This->fnCreateInstance(riid, ppv, pUnkOuter);
90 91
}

92 93 94
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
        TRACE("(%d)\n", dolock);
95

96 97 98 99
        if (dolock)
                DMSTYLE_LockModule();
        else
                DMSTYLE_UnlockModule();
100

101
        return S_OK;
102 103
}

104 105 106 107 108 109
static const IClassFactoryVtbl classfactory_vtbl = {
        ClassFactory_QueryInterface,
        ClassFactory_AddRef,
        ClassFactory_Release,
        ClassFactory_CreateInstance,
        ClassFactory_LockServer
110 111
};

112 113 114 115 116 117 118 119 120 121
static IClassFactoryImpl Section_CF = {{&classfactory_vtbl}, create_direct_music_section};
static IClassFactoryImpl Style_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicStyleImpl};
static IClassFactoryImpl ChordTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicChordTrack};
static IClassFactoryImpl CommandTrack_CF = {{&classfactory_vtbl},
                                            DMUSIC_CreateDirectMusicCommandTrack};
static IClassFactoryImpl StyleTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicStyleTrack};
static IClassFactoryImpl MotifTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicMotifTrack};
static IClassFactoryImpl AuditionTrack_CF = {{&classfactory_vtbl},
                                             DMUSIC_CreateDirectMusicAuditionTrack};
static IClassFactoryImpl MuteTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicMuteTrack};
122

123 124 125 126 127
/******************************************************************
 *		DllMain
 *
 *
 */
128 129
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
	if (fdwReason == DLL_PROCESS_ATTACH) {
130
            instance = hinstDLL;
131 132
            DisableThreadLibraryCalls(hinstDLL);
		/* FIXME: Initialisation */
133
	} else if (fdwReason == DLL_PROCESS_DETACH) {
134 135 136 137 138 139 140 141 142 143 144 145
		/* FIXME: Cleanup */
	}

	return TRUE;
}


/******************************************************************
 *		DllCanUnloadNow (DMSTYLE.1)
 *
 *
 */
146
HRESULT WINAPI DllCanUnloadNow(void) {
147
	return DMSTYLE_refCount != 0 ? S_FALSE : S_OK;
148 149 150 151
}


/******************************************************************
152
 *		DllGetClassObject (DMSTYLE.@)
153 154 155
 *
 *
 */
156
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
157
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
158 159
    
	if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSection) && IsEqualIID (riid, &IID_IClassFactory)) {
160
                *ppv = &Section_CF;
161 162 163
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicStyle) && IsEqualIID (riid, &IID_IClassFactory)) {
164
                *ppv = &Style_CF;
165 166 167
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
168
                *ppv = &ChordTrack_CF;
169 170 171
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;	
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCommandTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
172
                *ppv = &CommandTrack_CF;
173 174 175
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicStyleTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
176
                *ppv = &StyleTrack_CF;
177 178 179
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMotifTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
180
                *ppv = &MotifTrack_CF;
181 182 183
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicAuditionTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
184
                *ppv = &AuditionTrack_CF;
185 186 187
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMuteTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
188
                *ppv = &MuteTrack_CF;
189 190
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;		
191
	}
192

193
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
194 195
    return CLASS_E_CLASSNOTAVAILABLE;
}
196 197 198 199 200 201

/***********************************************************************
 *		DllRegisterServer (DMSTYLE.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
202
    return __wine_register_resources( instance );
203 204 205 206 207 208 209
}

/***********************************************************************
 *		DllUnregisterServer (DMSTYLE.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
210
    return __wine_unregister_resources( instance );
211
}