winecfg: Update Portuguese translation.
[wine/testsucceed.git] / dlls / avifil32 / factory.c
blobd1246e8e99cfa21c0216131de82705b15e5665bf
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"
30 #include "initguid.h"
31 #include "vfw.h"
32 #include "avifile_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38 HMODULE AVIFILE_hModule = NULL;
40 static BOOL AVIFILE_bLocked;
41 static UINT AVIFILE_uUseCount;
43 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
44 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
45 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
46 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
47 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
49 static const IClassFactoryVtbl iclassfact = {
50 IClassFactory_fnQueryInterface,
51 IClassFactory_fnAddRef,
52 IClassFactory_fnRelease,
53 IClassFactory_fnCreateInstance,
54 IClassFactory_fnLockServer
57 typedef struct
59 /* IUnknown fields */
60 const IClassFactoryVtbl *lpVtbl;
61 DWORD dwRef;
63 CLSID clsid;
64 } IClassFactoryImpl;
66 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
67 LPVOID *ppv)
69 IClassFactoryImpl *pClassFactory = NULL;
70 HRESULT hr;
72 *ppv = NULL;
74 pClassFactory = HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory));
75 if (pClassFactory == NULL)
76 return E_OUTOFMEMORY;
78 pClassFactory->lpVtbl = &iclassfact;
79 pClassFactory->dwRef = 0;
80 pClassFactory->clsid = *pclsid;
82 hr = IClassFactory_QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
83 if (FAILED(hr)) {
84 HeapFree(GetProcessHeap(), 0, pClassFactory);
85 *ppv = NULL;
88 return hr;
91 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
92 REFIID riid,LPVOID *ppobj)
94 TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
96 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
97 (IsEqualGUID(&IID_IClassFactory, riid))) {
98 *ppobj = iface;
99 IClassFactory_AddRef(iface);
100 return S_OK;
103 return E_NOINTERFACE;
106 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
108 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
110 TRACE("(%p)\n", iface);
112 return ++(This->dwRef);
115 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
117 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
119 TRACE("(%p)\n", iface);
120 if ((--(This->dwRef)) > 0)
121 return This->dwRef;
123 HeapFree(GetProcessHeap(), 0, This);
125 return 0;
128 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
129 LPUNKNOWN pOuter,
130 REFIID riid,LPVOID *ppobj)
132 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
134 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
135 ppobj);
137 if (ppobj == NULL || pOuter != NULL)
138 return E_FAIL;
139 *ppobj = NULL;
141 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
142 return AVIFILE_CreateAVIFile(riid,ppobj);
143 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
144 return AVIFILE_CreateICMStream(riid,ppobj);
145 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
146 return AVIFILE_CreateWAVFile(riid,ppobj);
147 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
148 return AVIFILE_CreateACMStream(riid,ppobj);
150 return E_NOINTERFACE;
153 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
155 TRACE("(%p,%d)\n",iface,dolock);
157 AVIFILE_bLocked = dolock;
159 return S_OK;
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 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
187 if (pclsid == NULL || piid == NULL || ppv == NULL)
188 return E_FAIL;
190 return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193 /*****************************************************************************
194 * DllCanUnloadNow (AVIFIL32.@)
196 HRESULT WINAPI DllCanUnloadNow(void)
198 return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
201 /*****************************************************************************
202 * DllMain [AVIFIL32.init]
204 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
206 TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
208 switch (fdwReason) {
209 case DLL_PROCESS_ATTACH:
210 DisableThreadLibraryCalls(hInstDll);
211 AVIFILE_hModule = hInstDll;
212 break;
213 case DLL_PROCESS_DETACH:
214 break;
217 return TRUE;