dmscript_main.c 8.29 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
static HINSTANCE instance;
42 43
LONG DMSCRIPT_refCount = 0;

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

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

53
        return CLASS_E_CLASSNOTAVAILABLE;
54 55 56
}

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

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

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

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

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

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

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

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

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

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

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

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

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

117
        return S_OK;
118 119
}

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

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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};
143 144 145 146 147 148

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

	return TRUE;
}


/******************************************************************
160
 *		DllCanUnloadNow (DMSCRIPT.@)
161 162 163
 *
 *
 */
164 165
HRESULT WINAPI DllCanUnloadNow(void)
{
166
	return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
167 168 169 170
}


/******************************************************************
171
 *		DllGetClassObject (DMSCRIPT.@)
172 173 174
 *
 *
 */
175 176
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
177
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
178
    if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
179
      *ppv = &ScriptAutoImplSegment_CF;
180 181 182
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
183
      *ppv = &ScriptTrack_CF;
184 185 186
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
187
      *ppv = &AudioVBScript_CF;
188 189 190
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
191
      *ppv = &Script_CF;
192 193 194
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
195
      *ppv = &ScriptAutoImplPerformance_CF;
196 197
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
198
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
199
      *ppv = &ScriptSourceCodeLoader_CF;
200 201 202
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
203
      *ppv = &ScriptAutoImplSegmentState_CF;
204 205 206
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
207
      *ppv = &ScriptAutoImplAudioPathConfig_CF;
208 209 210
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
211
      *ppv = &ScriptAutoImplAudioPath_CF;
212 213 214
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
215
      *ppv = &ScriptAutoImplSong_CF;
216 217 218 219
      IClassFactory_AddRef((IClassFactory*)*ppv);
      return S_OK;
	}		

220
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
221 222
    return CLASS_E_CLASSNOTAVAILABLE;
}
223 224


225 226 227 228 229
/***********************************************************************
 *		DllRegisterServer (DMSCRIPT.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
230
    return __wine_register_resources( instance );
231 232 233 234 235 236 237
}

/***********************************************************************
 *		DllUnregisterServer (DMSCRIPT.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
238
    return __wine_unregister_resources( instance );
239
}