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
32 #include "avifile_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38 HMODULE AVIFILE_hModule = NULL;
40 static BOOL AVIFILE_bLocked;
41 static UINT AVIFILE_uUseCount;
43 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
44 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
45 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
46 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
47 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
49 static const IClassFactoryVtbl iclassfact = {
50 IClassFactory_fnQueryInterface,
51 IClassFactory_fnAddRef,
52 IClassFactory_fnRelease,
53 IClassFactory_fnCreateInstance,
54 IClassFactory_fnLockServer
60 const IClassFactoryVtbl *lpVtbl;
66 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
69 IClassFactoryImpl *pClassFactory = NULL;
74 pClassFactory = HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory));
75 if (pClassFactory == NULL)
78 pClassFactory->lpVtbl = &iclassfact;
79 pClassFactory->dwRef = 0;
80 pClassFactory->clsid = *pclsid;
82 hr = IClassFactory_QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
84 HeapFree(GetProcessHeap(), 0, pClassFactory);
91 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
92 REFIID riid,LPVOID *ppobj)
94 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
96 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
97 (IsEqualGUID(&IID_IClassFactory, riid))) {
99 IClassFactory_AddRef(iface);
103 return E_NOINTERFACE;
106 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
108 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
110 TRACE("(%p)\n", iface);
112 return ++(This->dwRef);
115 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
117 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
119 TRACE("(%p)\n", iface);
120 if ((--(This->dwRef)) > 0)
123 HeapFree(GetProcessHeap(), 0, This);
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 DllGetClassObject(REFCLSID 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 HRESULT WINAPI 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,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
209 case DLL_PROCESS_ATTACH:
210 DisableThreadLibraryCalls(hInstDll);
211 AVIFILE_hModule = hInstDll;
213 case DLL_PROCESS_DETACH: