2 * Copyright 2002 Michael Günnewig
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
39 #include "avifile_private.h"
41 HMODULE AVIFILE_hModule = NULL;
43 static BOOL AVIFILE_bLocked;
44 static UINT AVIFILE_uUseCount;
46 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
47 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
48 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
49 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
50 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
52 static const IClassFactoryVtbl iclassfact = {
53 IClassFactory_fnQueryInterface,
54 IClassFactory_fnAddRef,
55 IClassFactory_fnRelease,
56 IClassFactory_fnCreateInstance,
57 IClassFactory_fnLockServer
63 const IClassFactoryVtbl *lpVtbl;
69 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
72 IClassFactoryImpl *pClassFactory = NULL;
77 pClassFactory = HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory));
78 if (pClassFactory == NULL)
81 pClassFactory->lpVtbl = &iclassfact;
82 pClassFactory->dwRef = 0;
83 memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
85 hr = IClassFactory_QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
87 HeapFree(GetProcessHeap(), 0, pClassFactory);
94 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
95 REFIID riid,LPVOID *ppobj)
97 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
99 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
100 (IsEqualGUID(&IID_IClassFactory, riid))) {
102 IClassFactory_AddRef(iface);
106 return E_NOINTERFACE;
109 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
111 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113 TRACE("(%p)\n", iface);
115 return ++(This->dwRef);
118 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
120 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
122 TRACE("(%p)\n", iface);
123 if ((--(This->dwRef)) > 0)
126 HeapFree(GetProcessHeap(), 0, This);
131 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
133 REFIID riid,LPVOID *ppobj)
135 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
137 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
140 if (ppobj == NULL || pOuter != NULL)
144 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
145 return AVIFILE_CreateAVIFile(riid,ppobj);
146 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
147 return AVIFILE_CreateICMStream(riid,ppobj);
148 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
149 return AVIFILE_CreateWAVFile(riid,ppobj);
150 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
151 return AVIFILE_CreateACMStream(riid,ppobj);
153 return E_NOINTERFACE;
156 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
158 TRACE("(%p,%d)\n",iface,dolock);
160 AVIFILE_bLocked = dolock;
165 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
167 #define SLASH(w) ((w) == '/' || (w) == '\\')
171 for (szCur = szPath + lstrlenW(szPath);
172 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
183 /***********************************************************************
184 * DllGetClassObject (AVIFIL32.@)
186 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
188 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
190 if (pclsid == NULL || piid == NULL || ppv == NULL)
193 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
196 /*****************************************************************************
197 * DllCanUnloadNow (AVIFIL32.@)
199 HRESULT WINAPI DllCanUnloadNow(void)
201 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
204 /*****************************************************************************
205 * DllMain [AVIFIL32.init]
207 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
209 TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
212 case DLL_PROCESS_ATTACH:
213 DisableThreadLibraryCalls(hInstDll);
214 AVIFILE_hModule = (HMODULE)hInstDll;
216 case DLL_PROCESS_DETACH: