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
19 #define COM_NO_WINDOWS_H
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38 #include "avifile_private.h"
40 HMODULE AVIFILE_hModule = NULL;
42 BOOL AVIFILE_bLocked = FALSE;
43 UINT AVIFILE_uUseCount = 0;
45 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
46 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
47 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
48 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
49 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
51 static IClassFactoryVtbl iclassfact = {
52 IClassFactory_fnQueryInterface,
53 IClassFactory_fnAddRef,
54 IClassFactory_fnRelease,
55 IClassFactory_fnCreateInstance,
56 IClassFactory_fnLockServer
62 IClassFactoryVtbl *lpVtbl;
68 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
71 IClassFactoryImpl *pClassFactory = NULL;
76 pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
77 if (pClassFactory == NULL)
80 pClassFactory->lpVtbl = &iclassfact;
81 pClassFactory->dwRef = 0;
82 memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
84 hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
86 LocalFree((HLOCAL)pClassFactory);
93 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
94 REFIID riid,LPVOID *ppobj)
96 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
98 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
99 (IsEqualGUID(&IID_IClassFactory, riid))) {
101 IClassFactory_AddRef(iface);
105 return E_NOINTERFACE;
108 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
110 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
112 TRACE("(%p)\n", iface);
114 return ++(This->dwRef);
117 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
119 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
121 TRACE("(%p)\n", iface);
122 if ((--(This->dwRef)) > 0)
128 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
130 REFIID riid,LPVOID *ppobj)
132 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
134 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
137 if (ppobj == NULL || pOuter != NULL)
141 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
142 return AVIFILE_CreateAVIFile(riid,ppobj);
143 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
144 return AVIFILE_CreateICMStream(riid,ppobj);
145 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
146 return AVIFILE_CreateWAVFile(riid,ppobj);
147 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
148 return AVIFILE_CreateACMStream(riid,ppobj);
150 return E_NOINTERFACE;
153 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
155 TRACE("(%p,%d)\n",iface,dolock);
157 AVIFILE_bLocked = dolock;
162 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
164 #define SLASH(w) ((w) == '/' || (w) == '\\')
168 for (szCur = szPath + lstrlenW(szPath);
169 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
180 /***********************************************************************
181 * DllGetClassObject (AVIFIL32.@)
183 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
185 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
187 if (pclsid == NULL || piid == NULL || ppv == NULL)
190 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193 /*****************************************************************************
194 * DllCanUnloadNow (AVIFIL32.@)
196 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
198 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
201 /*****************************************************************************
202 * DllMain [AVIFIL32.init]
204 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
206 TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
209 case DLL_PROCESS_ATTACH:
210 DisableThreadLibraryCalls(hInstDll);
211 AVIFILE_hModule = (HMODULE)hInstDll;
213 case DLL_PROCESS_DETACH: