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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
33 #include "avifile_private.h"
35 HMODULE AVIFILE_hModule = (HMODULE)NULL;
37 BOOL AVIFILE_bLocked = FALSE;
38 UINT AVIFILE_uUseCount = 0;
40 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
41 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
42 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
43 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
44 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
46 static ICOM_VTABLE(IClassFactory) iclassfact = {
47 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
48 IClassFactory_fnQueryInterface,
49 IClassFactory_fnAddRef,
50 IClassFactory_fnRelease,
51 IClassFactory_fnCreateInstance,
52 IClassFactory_fnLockServer
58 ICOM_VFIELD(IClassFactory);
64 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
67 IClassFactoryImpl *pClassFactory = NULL;
72 pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
73 if (pClassFactory == NULL)
76 ICOM_VTBL(pClassFactory) = &iclassfact;
77 pClassFactory->dwRef = 0;
78 memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
80 hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
82 LocalFree((HLOCAL)pClassFactory);
89 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
90 REFIID riid,LPVOID *ppobj)
92 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
94 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
95 (IsEqualGUID(&IID_IClassFactory, riid))) {
97 IClassFactory_AddRef(iface);
101 return E_NOINTERFACE;
104 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
106 ICOM_THIS(IClassFactoryImpl,iface);
108 TRACE("(%p)\n", iface);
110 return ++(This->dwRef);
113 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
115 ICOM_THIS(IClassFactoryImpl,iface);
117 TRACE("(%p)\n", iface);
118 if ((--(This->dwRef)) > 0)
124 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
126 REFIID riid,LPVOID *ppobj)
128 ICOM_THIS(IClassFactoryImpl,iface);
130 FIXME("(%p,%p,%s,%p): partial stub!\n", iface, pOuter, debugstr_guid(riid),
133 if (ppobj == NULL || pOuter != NULL)
137 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
138 return AVIFILE_CreateAVIFile(riid,ppobj);
139 /* if (IsEqualGUID(&CLSID_ICMStream, &This->clsid)) */
140 /* return AVIFILE_CreateICMStream(riid,ppobj); */
141 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
142 return AVIFILE_CreateWAVFile(riid,ppobj);
143 /* if (IsEqualGUID(&CLSID_ACMStream, &This->clsid)) */
144 /* return AVIFILE_CreateACMStream(riid,ppobj); */
146 return E_NOINTERFACE;
149 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
151 TRACE("(%p,%d)\n",iface,dolock);
153 AVIFILE_bLocked = dolock;
158 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
160 #define SLASH(w) ((w) == '/' || (w) == '\\')
164 for (szCur = szPath + lstrlenW(szPath);
165 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
176 /***********************************************************************
177 * DllGetClassObject (AVIFIL32.@)
179 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
181 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
183 if (pclsid == NULL || piid == NULL || ppv == NULL)
186 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
189 /*****************************************************************************
190 * DllCanUnloadNow (AVIFIL32.@)
192 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
194 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
197 /*****************************************************************************
198 * AVIFILE_DllMain [internal]
200 BOOL WINAPI AVIFILE_DllMain(HINSTANCE hInstDll, DWORD fdwReason,
203 TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
206 case DLL_PROCESS_ATTACH:
207 if (AVIFILE_hModule == (HMODULE)NULL)
208 AVIFILE_hModule = (HMODULE)hInstDll;
210 case DLL_PROCESS_DETACH:
212 case DLL_THREAD_ATTACH:
214 case DLL_THREAD_DETACH: