dmscript_main.c 7.55 KB
Newer Older
1 2
/* DirectMusicScript 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

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 "dmscript_private.h"
37
#include "dmobject.h"
38

39
WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
40

41 42
LONG DMSCRIPT_refCount = 0;

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

48 49 50
static HRESULT WINAPI create_unimpl_instance(REFIID riid, void **ppv, IUnknown *pUnkOuter)
{
        FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
51

52
        return CLASS_E_CLASSNOTAVAILABLE;
53 54 55
}

/******************************************************************
56
 *      IClassFactory implementation
57
 */
58 59 60
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
        return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
61 62
}

63 64 65 66
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
        if (ppv == NULL)
                return E_POINTER;
67

68 69 70 71 72 73 74 75 76
        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;
        }
77

78 79 80
        *ppv = iface;
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
81 82
}

83 84 85
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
        DMSCRIPT_LockModule();
86

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

90 91 92
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
        DMSCRIPT_UnlockModule();
93

94
        return 1; /* non-heap based object */
95 96
}

97 98 99 100
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
        REFIID riid, void **ppv)
{
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
101

102
        TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
103

104
        return This->fnCreateInstance(riid, ppv, pUnkOuter);
105 106
}

107 108 109
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
        TRACE("(%d)\n", dolock);
110

111 112 113 114
        if (dolock)
                DMSCRIPT_LockModule();
        else
                DMSCRIPT_UnlockModule();
115

116
        return S_OK;
117 118
}

119 120 121 122 123 124
static const IClassFactoryVtbl classfactory_vtbl = {
        ClassFactory_QueryInterface,
        ClassFactory_AddRef,
        ClassFactory_Release,
        ClassFactory_CreateInstance,
        ClassFactory_LockServer
125 126
};

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
static IClassFactoryImpl ScriptAutoImplSegment_CF = {{&classfactory_vtbl}, create_unimpl_instance};
static IClassFactoryImpl ScriptTrack_CF = {{&classfactory_vtbl},
                                           DMUSIC_CreateDirectMusicScriptTrack};
static IClassFactoryImpl AudioVBScript_CF = {{&classfactory_vtbl}, create_unimpl_instance};
static IClassFactoryImpl Script_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicScriptImpl};
static IClassFactoryImpl ScriptAutoImplPerformance_CF = {{&classfactory_vtbl},
                                                         create_unimpl_instance};
static IClassFactoryImpl ScriptSourceCodeLoader_CF = {{&classfactory_vtbl}, create_unimpl_instance};
static IClassFactoryImpl ScriptAutoImplSegmentState_CF = {{&classfactory_vtbl},
                                                          create_unimpl_instance};
static IClassFactoryImpl ScriptAutoImplAudioPathConfig_CF = {{&classfactory_vtbl},
                                                             create_unimpl_instance};
static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {{&classfactory_vtbl},
                                                       create_unimpl_instance};
static IClassFactoryImpl ScriptAutoImplSong_CF = {{&classfactory_vtbl}, create_unimpl_instance};
142 143

/******************************************************************
144
 *		DllCanUnloadNow (DMSCRIPT.@)
145 146 147
 *
 *
 */
148 149
HRESULT WINAPI DllCanUnloadNow(void)
{
150
	return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
151 152 153 154
}


/******************************************************************
155
 *		DllGetClassObject (DMSCRIPT.@)
156 157 158
 *
 *
 */
159 160
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
161
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
162
    if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
163
      *ppv = &ScriptAutoImplSegment_CF;
164 165 166
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
167
      *ppv = &ScriptTrack_CF;
168 169 170
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
171
      *ppv = &AudioVBScript_CF;
172 173 174
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
175
      *ppv = &Script_CF;
176 177 178
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
179
      *ppv = &ScriptAutoImplPerformance_CF;
180 181
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
182
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
183
      *ppv = &ScriptSourceCodeLoader_CF;
184 185 186
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
187
      *ppv = &ScriptAutoImplSegmentState_CF;
188 189 190
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
191
      *ppv = &ScriptAutoImplAudioPathConfig_CF;
192 193 194
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
195
      *ppv = &ScriptAutoImplAudioPath_CF;
196 197 198
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
199
      *ppv = &ScriptAutoImplSong_CF;
200 201 202 203
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	}		

204
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
205 206
    return CLASS_E_CLASSNOTAVAILABLE;
}