1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2002 Michael Günnewig
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19*44836a6eSAmine Khaldi #include <stdarg.h>
20*44836a6eSAmine Khaldi
21*44836a6eSAmine Khaldi #define COBJMACROS
22*44836a6eSAmine Khaldi
23*44836a6eSAmine Khaldi #include "windef.h"
24*44836a6eSAmine Khaldi #include "winbase.h"
25*44836a6eSAmine Khaldi #include "wingdi.h"
26*44836a6eSAmine Khaldi #include "winuser.h"
27*44836a6eSAmine Khaldi #include "winerror.h"
28*44836a6eSAmine Khaldi #include "ole2.h"
29*44836a6eSAmine Khaldi #include "rpcproxy.h"
30*44836a6eSAmine Khaldi
31*44836a6eSAmine Khaldi #include "initguid.h"
32*44836a6eSAmine Khaldi #include "vfw.h"
33c2c66affSColin Finck #include "avifile_private.h"
34c2c66affSColin Finck
35*44836a6eSAmine Khaldi #include "wine/debug.h"
36*44836a6eSAmine Khaldi
37*44836a6eSAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38c2c66affSColin Finck
39c2c66affSColin Finck HMODULE AVIFILE_hModule = NULL;
40c2c66affSColin Finck
41c2c66affSColin Finck static BOOL AVIFILE_bLocked;
42c2c66affSColin Finck static UINT AVIFILE_uUseCount;
43c2c66affSColin Finck
44c2c66affSColin Finck typedef struct
45c2c66affSColin Finck {
46c2c66affSColin Finck IClassFactory IClassFactory_iface;
47c2c66affSColin Finck LONG ref;
48c2c66affSColin Finck CLSID clsid;
49c2c66affSColin Finck } IClassFactoryImpl;
50c2c66affSColin Finck
impl_from_IClassFactory(IClassFactory * iface)51c2c66affSColin Finck static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
52c2c66affSColin Finck {
53c2c66affSColin Finck return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54c2c66affSColin Finck }
55c2c66affSColin Finck
IClassFactory_fnQueryInterface(IClassFactory * iface,REFIID riid,void ** ppobj)56c2c66affSColin Finck static HRESULT WINAPI IClassFactory_fnQueryInterface(IClassFactory *iface, REFIID riid,
57c2c66affSColin Finck void **ppobj)
58c2c66affSColin Finck {
59c2c66affSColin Finck TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
60c2c66affSColin Finck
61c2c66affSColin Finck if ((IsEqualGUID(&IID_IUnknown, riid)) ||
62c2c66affSColin Finck (IsEqualGUID(&IID_IClassFactory, riid))) {
63c2c66affSColin Finck *ppobj = iface;
64c2c66affSColin Finck IClassFactory_AddRef(iface);
65c2c66affSColin Finck return S_OK;
66c2c66affSColin Finck }
67c2c66affSColin Finck
68c2c66affSColin Finck return E_NOINTERFACE;
69c2c66affSColin Finck }
70c2c66affSColin Finck
IClassFactory_fnAddRef(IClassFactory * iface)71c2c66affSColin Finck static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
72c2c66affSColin Finck {
73c2c66affSColin Finck IClassFactoryImpl *This = impl_from_IClassFactory(iface);
74c2c66affSColin Finck ULONG ref = InterlockedIncrement(&This->ref);
75c2c66affSColin Finck
76c2c66affSColin Finck TRACE("(%p) ref = %u\n", This, ref);
77c2c66affSColin Finck return ref;
78c2c66affSColin Finck }
79c2c66affSColin Finck
IClassFactory_fnRelease(IClassFactory * iface)80c2c66affSColin Finck static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
81c2c66affSColin Finck {
82c2c66affSColin Finck IClassFactoryImpl *This = impl_from_IClassFactory(iface);
83c2c66affSColin Finck ULONG ref = InterlockedDecrement(&This->ref);
84c2c66affSColin Finck
85c2c66affSColin Finck TRACE("(%p) ref = %u\n", This, ref);
86c2c66affSColin Finck
87c2c66affSColin Finck if(!ref)
88c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, This);
89c2c66affSColin Finck
90c2c66affSColin Finck return ref;
91c2c66affSColin Finck }
92c2c66affSColin Finck
IClassFactory_fnCreateInstance(IClassFactory * iface,IUnknown * pOuter,REFIID riid,void ** ppobj)93c2c66affSColin Finck static HRESULT WINAPI IClassFactory_fnCreateInstance(IClassFactory *iface, IUnknown *pOuter,
94c2c66affSColin Finck REFIID riid, void **ppobj)
95c2c66affSColin Finck {
96c2c66affSColin Finck IClassFactoryImpl *This = impl_from_IClassFactory(iface);
97c2c66affSColin Finck
98c2c66affSColin Finck TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
99c2c66affSColin Finck ppobj);
100c2c66affSColin Finck
101c2c66affSColin Finck if (!ppobj)
102c2c66affSColin Finck return E_INVALIDARG;
103c2c66affSColin Finck *ppobj = NULL;
104c2c66affSColin Finck
105c2c66affSColin Finck if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
106c2c66affSColin Finck return E_INVALIDARG;
107c2c66affSColin Finck
108c2c66affSColin Finck if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
109c2c66affSColin Finck return AVIFILE_CreateAVIFile(pOuter, riid, ppobj);
110c2c66affSColin Finck if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
111c2c66affSColin Finck return AVIFILE_CreateWAVFile(pOuter, riid, ppobj);
112c2c66affSColin Finck
113c2c66affSColin Finck if (pOuter)
114c2c66affSColin Finck return CLASS_E_NOAGGREGATION;
115c2c66affSColin Finck
116c2c66affSColin Finck if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
117c2c66affSColin Finck return AVIFILE_CreateICMStream(riid,ppobj);
118c2c66affSColin Finck if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
119c2c66affSColin Finck return AVIFILE_CreateACMStream(riid,ppobj);
120c2c66affSColin Finck
121c2c66affSColin Finck return E_NOINTERFACE;
122c2c66affSColin Finck }
123c2c66affSColin Finck
IClassFactory_fnLockServer(IClassFactory * iface,BOOL dolock)124c2c66affSColin Finck static HRESULT WINAPI IClassFactory_fnLockServer(IClassFactory *iface, BOOL dolock)
125c2c66affSColin Finck {
126c2c66affSColin Finck TRACE("(%p,%d)\n",iface,dolock);
127c2c66affSColin Finck
128c2c66affSColin Finck AVIFILE_bLocked = dolock;
129c2c66affSColin Finck
130c2c66affSColin Finck return S_OK;
131c2c66affSColin Finck }
132c2c66affSColin Finck
133c2c66affSColin Finck static const IClassFactoryVtbl iclassfact = {
134c2c66affSColin Finck IClassFactory_fnQueryInterface,
135c2c66affSColin Finck IClassFactory_fnAddRef,
136c2c66affSColin Finck IClassFactory_fnRelease,
137c2c66affSColin Finck IClassFactory_fnCreateInstance,
138c2c66affSColin Finck IClassFactory_fnLockServer
139c2c66affSColin Finck };
140c2c66affSColin Finck
AVIFILE_CreateClassFactory(const CLSID * clsid,const IID * riid,void ** ppv)141c2c66affSColin Finck static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
142c2c66affSColin Finck {
143c2c66affSColin Finck IClassFactoryImpl *cf;
144c2c66affSColin Finck HRESULT hr;
145c2c66affSColin Finck
146c2c66affSColin Finck *ppv = NULL;
147c2c66affSColin Finck
148c2c66affSColin Finck cf = HeapAlloc(GetProcessHeap(), 0, sizeof(*cf));
149c2c66affSColin Finck if (!cf)
150c2c66affSColin Finck return E_OUTOFMEMORY;
151c2c66affSColin Finck
152c2c66affSColin Finck cf->IClassFactory_iface.lpVtbl = &iclassfact;
153c2c66affSColin Finck cf->ref = 1;
154c2c66affSColin Finck cf->clsid = *clsid;
155c2c66affSColin Finck
156c2c66affSColin Finck hr = IClassFactory_QueryInterface(&cf->IClassFactory_iface, riid, ppv);
157c2c66affSColin Finck IClassFactory_Release(&cf->IClassFactory_iface);
158c2c66affSColin Finck
159c2c66affSColin Finck return hr;
160c2c66affSColin Finck }
161c2c66affSColin Finck
AVIFILE_BasenameW(LPCWSTR szPath)162c2c66affSColin Finck LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
163c2c66affSColin Finck {
164c2c66affSColin Finck #define SLASH(w) ((w) == '/' || (w) == '\\')
165c2c66affSColin Finck
166c2c66affSColin Finck LPCWSTR szCur;
167c2c66affSColin Finck
168c2c66affSColin Finck for (szCur = szPath + lstrlenW(szPath);
169c2c66affSColin Finck szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
170c2c66affSColin Finck szCur--;
171c2c66affSColin Finck
172c2c66affSColin Finck if (szCur == szPath)
173c2c66affSColin Finck return szCur;
174c2c66affSColin Finck else
175c2c66affSColin Finck return szCur + 1;
176c2c66affSColin Finck
177c2c66affSColin Finck #undef SLASH
178c2c66affSColin Finck }
179c2c66affSColin Finck
180c2c66affSColin Finck /***********************************************************************
181c2c66affSColin Finck * DllGetClassObject (AVIFIL32.@)
182c2c66affSColin Finck */
DllGetClassObject(REFCLSID pclsid,REFIID piid,LPVOID * ppv)183c2c66affSColin Finck HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
184c2c66affSColin Finck {
185*44836a6eSAmine Khaldi HRESULT hr;
186*44836a6eSAmine Khaldi
187c2c66affSColin Finck TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
188c2c66affSColin Finck
189c2c66affSColin Finck if (pclsid == NULL || piid == NULL || ppv == NULL)
190c2c66affSColin Finck return E_FAIL;
191c2c66affSColin Finck
192*44836a6eSAmine Khaldi hr = AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193*44836a6eSAmine Khaldi if (SUCCEEDED(hr))
194*44836a6eSAmine Khaldi return hr;
195*44836a6eSAmine Khaldi
196*44836a6eSAmine Khaldi return avifil32_DllGetClassObject(pclsid,piid,ppv);
197c2c66affSColin Finck }
198c2c66affSColin Finck
199c2c66affSColin Finck /*****************************************************************************
200c2c66affSColin Finck * DllCanUnloadNow (AVIFIL32.@)
201c2c66affSColin Finck */
DllCanUnloadNow(void)202c2c66affSColin Finck HRESULT WINAPI DllCanUnloadNow(void)
203c2c66affSColin Finck {
204c2c66affSColin Finck return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
205c2c66affSColin Finck }
206c2c66affSColin Finck
207c2c66affSColin Finck /*****************************************************************************
208c2c66affSColin Finck * DllMain [AVIFIL32.init]
209c2c66affSColin Finck */
DllMain(HINSTANCE hInstDll,DWORD fdwReason,LPVOID lpvReserved)210c2c66affSColin Finck BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
211c2c66affSColin Finck {
212c2c66affSColin Finck TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
213c2c66affSColin Finck
214c2c66affSColin Finck switch (fdwReason) {
215c2c66affSColin Finck case DLL_PROCESS_ATTACH:
216c2c66affSColin Finck DisableThreadLibraryCalls(hInstDll);
217c2c66affSColin Finck AVIFILE_hModule = hInstDll;
218c2c66affSColin Finck break;
219c2c66affSColin Finck };
220c2c66affSColin Finck
221c2c66affSColin Finck return TRUE;
222c2c66affSColin Finck }
223c2c66affSColin Finck
224c2c66affSColin Finck /***********************************************************************
225c2c66affSColin Finck * DllRegisterServer (AVIFIL32.@)
226c2c66affSColin Finck */
DllRegisterServer(void)227c2c66affSColin Finck HRESULT WINAPI DllRegisterServer(void)
228c2c66affSColin Finck {
229c2c66affSColin Finck return __wine_register_resources( AVIFILE_hModule );
230c2c66affSColin Finck }
231c2c66affSColin Finck
232c2c66affSColin Finck /***********************************************************************
233c2c66affSColin Finck * DllUnregisterServer (AVIFIL32.@)
234c2c66affSColin Finck */
DllUnregisterServer(void)235c2c66affSColin Finck HRESULT WINAPI DllUnregisterServer(void)
236c2c66affSColin Finck {
237c2c66affSColin Finck return __wine_unregister_resources( AVIFILE_hModule );
238c2c66affSColin Finck }
239