Removed useless warning.
[wine/multimedia.git] / dlls / avifil32 / factory.c
blobc983953dc24cacb9502c4f844bd001c8a0e58daf
1 /*
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
20 #include <assert.h>
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winerror.h"
30 #include "ole2.h"
31 #include "vfw.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
37 #include "initguid.h"
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 ICOM_VTABLE(IClassFactory) iclassfact = {
52 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
53 IClassFactory_fnQueryInterface,
54 IClassFactory_fnAddRef,
55 IClassFactory_fnRelease,
56 IClassFactory_fnCreateInstance,
57 IClassFactory_fnLockServer
60 typedef struct
62 /* IUnknown fields */
63 ICOM_VFIELD(IClassFactory);
64 DWORD dwRef;
66 CLSID clsid;
67 } IClassFactoryImpl;
69 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
70 LPVOID *ppv)
72 IClassFactoryImpl *pClassFactory = NULL;
73 HRESULT hr;
75 *ppv = NULL;
77 pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
78 if (pClassFactory == NULL)
79 return E_OUTOFMEMORY;
81 pClassFactory->lpVtbl = &iclassfact;
82 pClassFactory->dwRef = 0;
83 memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
85 hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
86 if (FAILED(hr)) {
87 LocalFree((HLOCAL)pClassFactory);
88 *ppv = NULL;
91 return hr;
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))) {
101 *ppobj = iface;
102 IClassFactory_AddRef(iface);
103 return S_OK;
106 return E_NOINTERFACE;
109 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
111 ICOM_THIS(IClassFactoryImpl,iface);
113 TRACE("(%p)\n", iface);
115 return ++(This->dwRef);
118 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
120 ICOM_THIS(IClassFactoryImpl,iface);
122 TRACE("(%p)\n", iface);
123 if ((--(This->dwRef)) > 0)
124 return This->dwRef;
126 return 0;
129 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
130 LPUNKNOWN pOuter,
131 REFIID riid,LPVOID *ppobj)
133 ICOM_THIS(IClassFactoryImpl,iface);
135 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
136 ppobj);
138 if (ppobj == NULL || pOuter != NULL)
139 return E_FAIL;
140 *ppobj = NULL;
142 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
143 return AVIFILE_CreateAVIFile(riid,ppobj);
144 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
145 return AVIFILE_CreateICMStream(riid,ppobj);
146 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
147 return AVIFILE_CreateWAVFile(riid,ppobj);
148 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
149 return AVIFILE_CreateACMStream(riid,ppobj);
151 return E_NOINTERFACE;
154 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
156 TRACE("(%p,%d)\n",iface,dolock);
158 AVIFILE_bLocked = dolock;
160 return S_OK;
163 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
165 #define SLASH(w) ((w) == '/' || (w) == '\\')
167 LPCWSTR szCur;
169 for (szCur = szPath + lstrlenW(szPath);
170 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
171 szCur--;
173 if (szCur == szPath)
174 return szCur;
175 else
176 return szCur + 1;
178 #undef SLASH
181 /***********************************************************************
182 * DllGetClassObject (AVIFIL32.@)
184 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
186 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
188 if (pclsid == NULL || piid == NULL || ppv == NULL)
189 return E_FAIL;
191 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
194 /*****************************************************************************
195 * DllCanUnloadNow (AVIFIL32.@)
197 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
199 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
202 /*****************************************************************************
203 * DllMain [AVIFIL32.init]
205 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
207 TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
209 switch (fdwReason) {
210 case DLL_PROCESS_ATTACH:
211 DisableThreadLibraryCalls(hInstDll);
212 AVIFILE_hModule = (HMODULE)hInstDll;
213 break;
214 case DLL_PROCESS_DETACH:
215 break;
218 return TRUE;