main.c 5.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *     MultiMedia Streams Base Functions (AMSTREAM.DLL)
 *
 * Copyright 2004 Christian Costa
 *
 * This library 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.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23
 */

#include <stdarg.h>
#include <string.h>

24 25
#define COBJMACROS

26 27 28 29 30 31
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winerror.h"

#include "ole2.h"
32
#include "rpcproxy.h"
33 34 35 36 37 38 39 40

#include "amstream_private.h"
#include "amstream.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(amstream);

41
static HINSTANCE instance;
42 43 44 45 46 47 48
static DWORD dll_ref = 0;

/* For the moment, do nothing here. */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    switch(fdwReason) {
        case DLL_PROCESS_ATTACH:
49
            instance = hInstDLL;
50 51 52 53 54 55 56 57 58 59 60 61 62 63
            DisableThreadLibraryCalls(hInstDLL);
	    break;
	case DLL_PROCESS_DETACH:
	    break;
    }
    return TRUE;
}

/******************************************************************************
 * Multimedia Streams ClassFactory
 */
typedef struct {
    IClassFactory ITF_IClassFactory;

64
    LONG ref;
65 66 67 68 69 70 71 72 73 74 75 76
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
} IClassFactoryImpl;

struct object_creation_info
{
    const CLSID *clsid;
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
};

static const struct object_creation_info object_creation[] =
{
    { &CLSID_AMMultiMediaStream, AM_create },
77
    { &CLSID_AMDirectDrawStream, AM_create },
78
    { &CLSID_AMAudioData, AMAudioData_create },
79
    { &CLSID_MediaStreamFilter, MediaStreamFilter_create }
80 81 82 83 84
};

static HRESULT WINAPI
AMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
{
85
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
86 87 88 89 90 91 92 93 94 95 96 97 98

    if (IsEqualGUID(riid, &IID_IUnknown)
	|| IsEqualGUID(riid, &IID_IClassFactory))
    {
	IClassFactory_AddRef(iface);
	*ppobj = This;
	return S_OK;
    }

    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}

99 100
static ULONG WINAPI AMCF_AddRef(LPCLASSFACTORY iface)
{
101
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
102
    return InterlockedIncrement(&This->ref);
103 104
}

105 106
static ULONG WINAPI AMCF_Release(LPCLASSFACTORY iface)
{
107
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
108

109
    ULONG ref = InterlockedDecrement(&This->ref);
110 111 112 113 114 115 116 117 118

    if (ref == 0)
	HeapFree(GetProcessHeap(), 0, This);

    return ref;
}


static HRESULT WINAPI AMCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
119 120
					  REFIID riid, LPVOID *ppobj)
{
121
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
122 123 124 125 126
    HRESULT hres;
    LPUNKNOWN punk;
    
    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);

127
    *ppobj = NULL;
128
    hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
129 130 131
    if (SUCCEEDED(hres)) {
        hres = IUnknown_QueryInterface(punk, riid, ppobj);
        IUnknown_Release(punk);
132 133 134 135
    }
    return hres;
}

136 137
static HRESULT WINAPI AMCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
138
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
139 140 141 142
    FIXME("(%p)->(%d),stub!\n",This,dolock);
    return S_OK;
}

143
static const IClassFactoryVtbl DSCF_Vtbl =
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
{
    AMCF_QueryInterface,
    AMCF_AddRef,
    AMCF_Release,
    AMCF_CreateInstance,
    AMCF_LockServer
};

/*******************************************************************************
 * DllGetClassObject [AMSTREAM.@]
 * Retrieves class object from a DLL object
 *
 * NOTES
 *    Docs say returns STDAPI
 *
 * PARAMS
 *    rclsid [I] CLSID for the class object
 *    riid   [I] Reference to identifier of interface for class object
 *    ppv    [O] Address of variable to receive interface pointer for riid
 *
 * RETURNS
 *    Success: S_OK
 *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
 *             E_UNEXPECTED
 */
169
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
170
{
171
    unsigned int i;
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    IClassFactoryImpl *factory;
    
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
    
    if ( !IsEqualGUID( &IID_IClassFactory, riid )
	 && ! IsEqualGUID( &IID_IUnknown, riid) )
	return E_NOINTERFACE;

    for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
    {
	if (IsEqualGUID(object_creation[i].clsid, rclsid))
	    break;
    }

    if (i == sizeof(object_creation)/sizeof(object_creation[0]))
    {
	FIXME("%s: no class found.\n", debugstr_guid(rclsid));
	return CLASS_E_CLASSNOTAVAILABLE;
    }

    factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
    if (factory == NULL) return E_OUTOFMEMORY;

    factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
    factory->ref = 1;

    factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;

    *ppv = &(factory->ITF_IClassFactory);
    return S_OK;
}

/***********************************************************************
 *              DllCanUnloadNow (AMSTREAM.@)
 */
207
HRESULT WINAPI DllCanUnloadNow(void)
208 209 210
{
    return dll_ref != 0 ? S_FALSE : S_OK;
}
211 212 213 214 215 216

/***********************************************************************
 *		DllRegisterServer (AMSTREAM.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
217
    return __wine_register_resources( instance );
218 219 220 221 222 223 224
}

/***********************************************************************
 *		DllUnregisterServer (AMSTREAM.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
225
    return __wine_unregister_resources( instance );
226
}