ddraw: Avoid LPDIRECTDRAWSURFACE3.
[wine.git] / dlls / avifil32 / factory.c
blob295f11fd9865a883db4639053d084a7f722c82e7
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "ole2.h"
29 #include "rpcproxy.h"
31 #include "initguid.h"
32 #include "vfw.h"
33 #include "avifile_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
39 HMODULE AVIFILE_hModule = NULL;
41 static BOOL AVIFILE_bLocked;
42 static UINT AVIFILE_uUseCount;
44 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
45 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
46 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
47 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
48 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
50 static const IClassFactoryVtbl iclassfact = {
51 IClassFactory_fnQueryInterface,
52 IClassFactory_fnAddRef,
53 IClassFactory_fnRelease,
54 IClassFactory_fnCreateInstance,
55 IClassFactory_fnLockServer
58 typedef struct
60 /* IUnknown fields */
61 IClassFactory IClassFactory_iface;
62 DWORD dwRef;
64 CLSID clsid;
65 } IClassFactoryImpl;
67 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
69 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
72 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
73 LPVOID *ppv)
75 IClassFactoryImpl *pClassFactory = NULL;
76 HRESULT hr;
78 *ppv = NULL;
80 pClassFactory = HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory));
81 if (pClassFactory == NULL)
82 return E_OUTOFMEMORY;
84 pClassFactory->IClassFactory_iface.lpVtbl = &iclassfact;
85 pClassFactory->dwRef = 0;
86 pClassFactory->clsid = *pclsid;
88 hr = IClassFactory_QueryInterface(&pClassFactory->IClassFactory_iface, riid, ppv);
89 if (FAILED(hr)) {
90 HeapFree(GetProcessHeap(), 0, pClassFactory);
91 *ppv = NULL;
94 return hr;
97 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
98 REFIID riid,LPVOID *ppobj)
100 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
102 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
103 (IsEqualGUID(&IID_IClassFactory, riid))) {
104 *ppobj = iface;
105 IClassFactory_AddRef(iface);
106 return S_OK;
109 return E_NOINTERFACE;
112 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
114 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
116 TRACE("(%p)\n", iface);
118 return ++(This->dwRef);
121 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
123 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
125 TRACE("(%p)\n", iface);
126 if ((--(This->dwRef)) > 0)
127 return This->dwRef;
129 HeapFree(GetProcessHeap(), 0, This);
131 return 0;
134 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
135 LPUNKNOWN pOuter,
136 REFIID riid,LPVOID *ppobj)
138 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
140 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
141 ppobj);
143 if (ppobj == NULL || pOuter != NULL)
144 return E_FAIL;
145 *ppobj = NULL;
147 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
148 return AVIFILE_CreateAVIFile(riid,ppobj);
149 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
150 return AVIFILE_CreateICMStream(riid,ppobj);
151 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
152 return AVIFILE_CreateWAVFile(riid,ppobj);
153 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
154 return AVIFILE_CreateACMStream(riid,ppobj);
156 return E_NOINTERFACE;
159 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
161 TRACE("(%p,%d)\n",iface,dolock);
163 AVIFILE_bLocked = dolock;
165 return S_OK;
168 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
170 #define SLASH(w) ((w) == '/' || (w) == '\\')
172 LPCWSTR szCur;
174 for (szCur = szPath + lstrlenW(szPath);
175 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
176 szCur--;
178 if (szCur == szPath)
179 return szCur;
180 else
181 return szCur + 1;
183 #undef SLASH
186 /***********************************************************************
187 * DllGetClassObject (AVIFIL32.@)
189 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
191 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
193 if (pclsid == NULL || piid == NULL || ppv == NULL)
194 return E_FAIL;
196 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
199 /*****************************************************************************
200 * DllCanUnloadNow (AVIFIL32.@)
202 HRESULT WINAPI DllCanUnloadNow(void)
204 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
207 /*****************************************************************************
208 * DllMain [AVIFIL32.init]
210 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
212 TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
214 switch (fdwReason) {
215 case DLL_PROCESS_ATTACH:
216 DisableThreadLibraryCalls(hInstDll);
217 AVIFILE_hModule = hInstDll;
218 break;
219 case DLL_PROCESS_DETACH:
220 break;
223 return TRUE;
226 /***********************************************************************
227 * DllRegisterServer (AVIFIL32.@)
229 HRESULT WINAPI DllRegisterServer(void)
231 return __wine_register_resources( AVIFILE_hModule );
234 /***********************************************************************
235 * DllUnregisterServer (AVIFIL32.@)
237 HRESULT WINAPI DllUnregisterServer(void)
239 return __wine_unregister_resources( AVIFILE_hModule );