winhttp/tests: Initialize a variant with a known value.
[wine/multimedia.git] / dlls / amstream / main.c
blob067a929a80acdd632c05c21bef6f7483485d79b6
1 /*
2 * MultiMedia Streams Base Functions (AMSTREAM.DLL)
4 * Copyright 2004 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <stdarg.h>
25 #include <string.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "rpcproxy.h"
37 #include "amstream_private.h"
38 #include "amstream.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
44 static HINSTANCE instance;
45 static DWORD dll_ref = 0;
47 /* For the moment, do nothing here. */
48 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
50 switch(fdwReason) {
51 case DLL_PROCESS_ATTACH:
52 instance = hInstDLL;
53 DisableThreadLibraryCalls(hInstDLL);
54 break;
55 case DLL_PROCESS_DETACH:
56 break;
58 return TRUE;
61 /******************************************************************************
62 * Multimedia Streams ClassFactory
64 typedef struct {
65 IClassFactory ITF_IClassFactory;
67 LONG ref;
68 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
69 } IClassFactoryImpl;
71 struct object_creation_info
73 const CLSID *clsid;
74 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
77 static const struct object_creation_info object_creation[] =
79 { &CLSID_AMMultiMediaStream, AM_create },
80 { &CLSID_AMDirectDrawStream, AM_create },
81 { &CLSID_MediaStreamFilter, MediaStreamFilter_create }
84 static HRESULT WINAPI
85 AMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
87 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IClassFactory))
92 IClassFactory_AddRef(iface);
93 *ppobj = This;
94 return S_OK;
97 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
98 return E_NOINTERFACE;
101 static ULONG WINAPI AMCF_AddRef(LPCLASSFACTORY iface)
103 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
104 return InterlockedIncrement(&This->ref);
107 static ULONG WINAPI AMCF_Release(LPCLASSFACTORY iface)
109 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
111 ULONG ref = InterlockedDecrement(&This->ref);
113 if (ref == 0)
114 HeapFree(GetProcessHeap(), 0, This);
116 return ref;
120 static HRESULT WINAPI AMCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
121 REFIID riid, LPVOID *ppobj)
123 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
124 HRESULT hres;
125 LPUNKNOWN punk;
127 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129 *ppobj = NULL;
130 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
131 if (SUCCEEDED(hres)) {
132 hres = IUnknown_QueryInterface(punk, riid, ppobj);
133 IUnknown_Release(punk);
135 return hres;
138 static HRESULT WINAPI AMCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
140 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
141 FIXME("(%p)->(%d),stub!\n",This,dolock);
142 return S_OK;
145 static const IClassFactoryVtbl DSCF_Vtbl =
147 AMCF_QueryInterface,
148 AMCF_AddRef,
149 AMCF_Release,
150 AMCF_CreateInstance,
151 AMCF_LockServer
154 /*******************************************************************************
155 * DllGetClassObject [AMSTREAM.@]
156 * Retrieves class object from a DLL object
158 * NOTES
159 * Docs say returns STDAPI
161 * PARAMS
162 * rclsid [I] CLSID for the class object
163 * riid [I] Reference to identifier of interface for class object
164 * ppv [O] Address of variable to receive interface pointer for riid
166 * RETURNS
167 * Success: S_OK
168 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
169 * E_UNEXPECTED
171 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
173 unsigned int i;
174 IClassFactoryImpl *factory;
176 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
178 if ( !IsEqualGUID( &IID_IClassFactory, riid )
179 && ! IsEqualGUID( &IID_IUnknown, riid) )
180 return E_NOINTERFACE;
182 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
184 if (IsEqualGUID(object_creation[i].clsid, rclsid))
185 break;
188 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
190 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
191 return CLASS_E_CLASSNOTAVAILABLE;
194 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
195 if (factory == NULL) return E_OUTOFMEMORY;
197 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
198 factory->ref = 1;
200 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
202 *ppv = &(factory->ITF_IClassFactory);
203 return S_OK;
206 /***********************************************************************
207 * DllCanUnloadNow (AMSTREAM.@)
209 HRESULT WINAPI DllCanUnloadNow(void)
211 return dll_ref != 0 ? S_FALSE : S_OK;
214 /***********************************************************************
215 * DllRegisterServer (AMSTREAM.@)
217 HRESULT WINAPI DllRegisterServer(void)
219 return __wine_register_resources( instance );
222 /***********************************************************************
223 * DllUnregisterServer (AMSTREAM.@)
225 HRESULT WINAPI DllUnregisterServer(void)
227 return __wine_unregister_resources( instance );