dmband_main.c 4.92 KB
Newer Older
1 2
/* DirectMusicBand 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 "dmband_private.h"
21
#include "rpcproxy.h"
22
#include "dmobject.h"
23

24
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
25

26
static HINSTANCE instance;
27 28
LONG DMBAND_refCount = 0;

29
typedef struct {
30
        IClassFactory IClassFactory_iface;
31
        HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ret_iface);
32 33
} IClassFactoryImpl;

34
/******************************************************************
35
 *      IClassFactory implementation
36
 */
37 38 39
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
        return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
40 41
}

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
        if (ppv == NULL)
                return E_POINTER;

        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;
        IClassFactory_AddRef(iface);
        return S_OK;
60 61
}

62 63 64
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
        DMBAND_LockModule();
65

66
        return 2; /* non-heap based object */
67
}
68

69 70 71
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
        DMBAND_UnlockModule();
72

73
        return 1; /* non-heap based object */
74 75
}

76 77 78 79
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
        REFIID riid, void **ppv)
{
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80

81
        TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
82

83 84 85 86 87 88
        if (pUnkOuter) {
                *ppv = NULL;
                return CLASS_E_NOAGGREGATION;
        }

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

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

95 96 97 98
        if (dolock)
                DMBAND_LockModule();
        else
                DMBAND_UnlockModule();
99

100
        return S_OK;
101 102
}

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

111 112
static IClassFactoryImpl Band_CF = {{&classfactory_vtbl}, create_dmband};
static IClassFactoryImpl BandTrack_CF = {{&classfactory_vtbl}, create_dmbandtrack};
113 114 115 116 117 118

/******************************************************************
 *		DllMain
 *
 *
 */
119 120
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
	if (fdwReason == DLL_PROCESS_ATTACH) {
121
            instance = hinstDLL;
122 123 124 125 126 127 128 129
            DisableThreadLibraryCalls(hinstDLL);
	}

	return TRUE;
}


/******************************************************************
130
 *		DllCanUnloadNow (DMBAND.@)
131 132 133
 *
 *
 */
134 135
HRESULT WINAPI DllCanUnloadNow(void)
{
136
	return DMBAND_refCount != 0 ? S_FALSE : S_OK;
137 138 139 140
}


/******************************************************************
141
 *		DllGetClassObject (DMBAND.@)
142 143 144
 *
 *
 */
145 146
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
147
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
148

149 150 151 152 153
    if (IsEqualCLSID(rclsid, &CLSID_DirectMusicBand))
        return IClassFactory_QueryInterface(&Band_CF.IClassFactory_iface, riid, ppv);
    else if (IsEqualCLSID(rclsid, &CLSID_DirectMusicBandTrack))
        return IClassFactory_QueryInterface(&BandTrack_CF.IClassFactory_iface, riid, ppv);

154
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
155 156
    return CLASS_E_CLASSNOTAVAILABLE;
}
157 158 159 160 161 162

/***********************************************************************
 *		DllRegisterServer (DMBAND.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
163
    return __wine_register_resources( instance );
164 165 166 167 168 169 170
}

/***********************************************************************
 *		DllUnregisterServer (DMBAND.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
171
    return __wine_unregister_resources( instance );
172
}