winemac: Make show_window() and hide_window() tolerate being called when there's...
[wine.git] / dlls / avifil32 / factory.c
blobc74a716a7f4cd2990fbef840f7e30b8c87c29b28
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)
144 return E_INVALIDARG;
145 *ppobj = NULL;
147 if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
148 return E_INVALIDARG;
150 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
151 return AVIFILE_CreateAVIFile(pOuter, riid, ppobj);
152 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
153 return AVIFILE_CreateWAVFile(pOuter, riid, ppobj);
155 if (pOuter)
156 return CLASS_E_NOAGGREGATION;
158 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
159 return AVIFILE_CreateICMStream(riid,ppobj);
160 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
161 return AVIFILE_CreateACMStream(riid,ppobj);
163 return E_NOINTERFACE;
166 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
168 TRACE("(%p,%d)\n",iface,dolock);
170 AVIFILE_bLocked = dolock;
172 return S_OK;
175 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
177 #define SLASH(w) ((w) == '/' || (w) == '\\')
179 LPCWSTR szCur;
181 for (szCur = szPath + lstrlenW(szPath);
182 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
183 szCur--;
185 if (szCur == szPath)
186 return szCur;
187 else
188 return szCur + 1;
190 #undef SLASH
193 /***********************************************************************
194 * DllGetClassObject (AVIFIL32.@)
196 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
198 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
200 if (pclsid == NULL || piid == NULL || ppv == NULL)
201 return E_FAIL;
203 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
206 /*****************************************************************************
207 * DllCanUnloadNow (AVIFIL32.@)
209 HRESULT WINAPI DllCanUnloadNow(void)
211 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
214 /*****************************************************************************
215 * DllMain [AVIFIL32.init]
217 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
219 TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
221 switch (fdwReason) {
222 case DLL_PROCESS_ATTACH:
223 DisableThreadLibraryCalls(hInstDll);
224 AVIFILE_hModule = hInstDll;
225 break;
228 return TRUE;
231 /***********************************************************************
232 * DllRegisterServer (AVIFIL32.@)
234 HRESULT WINAPI DllRegisterServer(void)
236 return __wine_register_resources( AVIFILE_hModule );
239 /***********************************************************************
240 * DllUnregisterServer (AVIFIL32.@)
242 HRESULT WINAPI DllUnregisterServer(void)
244 return __wine_unregister_resources( AVIFILE_hModule );