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
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
34 #include "avifile_private.h"
36 HMODULE AVIFILE_hModule = NULL;
38 BOOL AVIFILE_bLocked = FALSE;
39 UINT AVIFILE_uUseCount = 0;
41 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
42 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
43 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
44 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
45 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
47 static ICOM_VTABLE(IClassFactory) iclassfact = {
48 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
49 IClassFactory_fnQueryInterface,
50 IClassFactory_fnAddRef,
51 IClassFactory_fnRelease,
52 IClassFactory_fnCreateInstance,
53 IClassFactory_fnLockServer
59 ICOM_VFIELD(IClassFactory);
65 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
68 IClassFactoryImpl *pClassFactory = NULL;
73 pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
74 if (pClassFactory == NULL)
77 pClassFactory->lpVtbl = &iclassfact;
78 pClassFactory->dwRef = 0;
79 memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
81 hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
83 LocalFree((HLOCAL)pClassFactory);
90 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
91 REFIID riid,LPVOID *ppobj)
93 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
95 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
96 (IsEqualGUID(&IID_IClassFactory, riid))) {
98 IClassFactory_AddRef(iface);
102 return E_NOINTERFACE;
105 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
107 ICOM_THIS(IClassFactoryImpl,iface);
109 TRACE("(%p)\n", iface);
111 return ++(This->dwRef);
114 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
116 ICOM_THIS(IClassFactoryImpl,iface);
118 TRACE("(%p)\n", iface);
119 if ((--(This->dwRef)) > 0)
125 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
127 REFIID riid,LPVOID *ppobj)
129 ICOM_THIS(IClassFactoryImpl,iface);
131 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
134 if (ppobj == NULL || pOuter != NULL)
138 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
139 return AVIFILE_CreateAVIFile(riid,ppobj);
140 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
141 return AVIFILE_CreateICMStream(riid,ppobj);
142 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
143 return AVIFILE_CreateWAVFile(riid,ppobj);
144 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
145 return AVIFILE_CreateACMStream(riid,ppobj);
147 return E_NOINTERFACE;
150 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
152 TRACE("(%p,%d)\n",iface,dolock);
154 AVIFILE_bLocked = dolock;
159 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
161 #define SLASH(w) ((w) == '/' || (w) == '\\')
165 for (szCur = szPath + lstrlenW(szPath);
166 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
177 /***********************************************************************
178 * DllGetClassObject (AVIFIL32.@)
180 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
182 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
184 if (pclsid == NULL || piid == NULL || ppv == NULL)
187 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
190 /*****************************************************************************
191 * DllCanUnloadNow (AVIFIL32.@)
193 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
195 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
198 /*****************************************************************************
199 * DllMain [AVIFIL32.init]
201 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
203 TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
206 case DLL_PROCESS_ATTACH:
207 if (AVIFILE_hModule == NULL)
208 AVIFILE_hModule = (HMODULE)hInstDll;
210 case DLL_PROCESS_DETACH:
212 case DLL_THREAD_ATTACH:
214 case DLL_THREAD_DETACH: