wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / avifil32 / factory.c
blob3775aa51a812e04faca405e79e10ffe3b328736b
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 typedef struct
46 IClassFactory IClassFactory_iface;
47 LONG ref;
48 CLSID clsid;
49 } IClassFactoryImpl;
51 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
53 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
56 static HRESULT WINAPI IClassFactory_fnQueryInterface(IClassFactory *iface, REFIID riid,
57 void **ppobj)
59 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
61 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
62 (IsEqualGUID(&IID_IClassFactory, riid))) {
63 *ppobj = iface;
64 IClassFactory_AddRef(iface);
65 return S_OK;
68 return E_NOINTERFACE;
71 static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
73 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
74 ULONG ref = InterlockedIncrement(&This->ref);
76 TRACE("(%p) ref = %u\n", This, ref);
77 return ref;
80 static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
82 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) ref = %u\n", This, ref);
87 if(!ref)
88 HeapFree(GetProcessHeap(), 0, This);
90 return ref;
93 static HRESULT WINAPI IClassFactory_fnCreateInstance(IClassFactory *iface, IUnknown *pOuter,
94 REFIID riid, void **ppobj)
96 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
99 ppobj);
101 if (!ppobj)
102 return E_INVALIDARG;
103 *ppobj = NULL;
105 if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
106 return E_INVALIDARG;
108 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
109 return AVIFILE_CreateAVIFile(pOuter, riid, ppobj);
110 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
111 return AVIFILE_CreateWAVFile(pOuter, riid, ppobj);
113 if (pOuter)
114 return CLASS_E_NOAGGREGATION;
116 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
117 return AVIFILE_CreateICMStream(riid,ppobj);
118 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
119 return AVIFILE_CreateACMStream(riid,ppobj);
121 return E_NOINTERFACE;
124 static HRESULT WINAPI IClassFactory_fnLockServer(IClassFactory *iface, BOOL dolock)
126 TRACE("(%p,%d)\n",iface,dolock);
128 AVIFILE_bLocked = dolock;
130 return S_OK;
133 static const IClassFactoryVtbl iclassfact = {
134 IClassFactory_fnQueryInterface,
135 IClassFactory_fnAddRef,
136 IClassFactory_fnRelease,
137 IClassFactory_fnCreateInstance,
138 IClassFactory_fnLockServer
141 static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
143 IClassFactoryImpl *cf;
144 HRESULT hr;
146 *ppv = NULL;
148 cf = HeapAlloc(GetProcessHeap(), 0, sizeof(*cf));
149 if (!cf)
150 return E_OUTOFMEMORY;
152 cf->IClassFactory_iface.lpVtbl = &iclassfact;
153 cf->ref = 1;
154 cf->clsid = *clsid;
156 hr = IClassFactory_QueryInterface(&cf->IClassFactory_iface, riid, ppv);
157 IClassFactory_Release(&cf->IClassFactory_iface);
159 return hr;
162 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
164 #define SLASH(w) ((w) == '/' || (w) == '\\')
166 LPCWSTR szCur;
168 for (szCur = szPath + lstrlenW(szPath);
169 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
170 szCur--;
172 if (szCur == szPath)
173 return szCur;
174 else
175 return szCur + 1;
177 #undef SLASH
180 /***********************************************************************
181 * DllGetClassObject (AVIFIL32.@)
183 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
185 HRESULT hr;
187 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
189 if (pclsid == NULL || piid == NULL || ppv == NULL)
190 return E_FAIL;
192 hr = AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193 if (SUCCEEDED(hr))
194 return hr;
196 return avifil32_DllGetClassObject(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;
221 return TRUE;
224 /***********************************************************************
225 * DllRegisterServer (AVIFIL32.@)
227 HRESULT WINAPI DllRegisterServer(void)
229 return __wine_register_resources( AVIFILE_hModule );
232 /***********************************************************************
233 * DllUnregisterServer (AVIFIL32.@)
235 HRESULT WINAPI DllUnregisterServer(void)
237 return __wine_unregister_resources( AVIFILE_hModule );