taskmgr: Update German translation.
[wine] / dlls / avifil32 / factory.c
1 /*
2  * Copyright 2002 Michael Günnewig
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
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
30 #include "initguid.h"
31 #include "vfw.h"
32 #include "avifile_private.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
37
38 HMODULE AVIFILE_hModule   = NULL;
39
40 static BOOL    AVIFILE_bLocked;
41 static UINT    AVIFILE_uUseCount;
42
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);
48
49 static const IClassFactoryVtbl iclassfact = {
50   IClassFactory_fnQueryInterface,
51   IClassFactory_fnAddRef,
52   IClassFactory_fnRelease,
53   IClassFactory_fnCreateInstance,
54   IClassFactory_fnLockServer
55 };
56
57 typedef struct
58 {
59   /* IUnknown fields */
60   const IClassFactoryVtbl *lpVtbl;
61   DWORD  dwRef;
62
63   CLSID  clsid;
64 } IClassFactoryImpl;
65
66 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
67                                           LPVOID *ppv)
68 {
69   IClassFactoryImpl *pClassFactory = NULL;
70   HRESULT            hr;
71
72   *ppv = NULL;
73
74   pClassFactory = HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory));
75   if (pClassFactory == NULL)
76     return E_OUTOFMEMORY;
77
78   pClassFactory->lpVtbl    = &iclassfact;
79   pClassFactory->dwRef     = 0;
80   pClassFactory->clsid     = *pclsid;
81
82   hr = IClassFactory_QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
83   if (FAILED(hr)) {
84     HeapFree(GetProcessHeap(), 0, pClassFactory);
85     *ppv = NULL;
86   }
87
88   return hr;
89 }
90
91 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
92                                                      REFIID riid,LPVOID *ppobj)
93 {
94   TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
95
96   if ((IsEqualGUID(&IID_IUnknown, riid)) ||
97       (IsEqualGUID(&IID_IClassFactory, riid))) {
98     *ppobj = iface;
99     IClassFactory_AddRef(iface);
100     return S_OK;
101   }
102
103   return E_NOINTERFACE;
104 }
105
106 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
107 {
108   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
109
110   TRACE("(%p)\n", iface);
111
112   return ++(This->dwRef);
113 }
114
115 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
116 {
117   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
118
119   TRACE("(%p)\n", iface);
120   if ((--(This->dwRef)) > 0)
121     return This->dwRef;
122
123   HeapFree(GetProcessHeap(), 0, This);
124
125   return 0;
126 }
127
128 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
129                                                      LPUNKNOWN pOuter,
130                                                      REFIID riid,LPVOID *ppobj)
131 {
132   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
133
134   TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
135         ppobj);
136
137   if (ppobj == NULL || pOuter != NULL)
138     return E_FAIL;
139   *ppobj = NULL;
140
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);
149
150   return E_NOINTERFACE;
151 }
152
153 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
154 {
155   TRACE("(%p,%d)\n",iface,dolock);
156
157   AVIFILE_bLocked = dolock;
158
159   return S_OK;
160 }
161
162 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
163 {
164 #define SLASH(w) ((w) == '/' || (w) == '\\')
165
166   LPCWSTR szCur;
167
168   for (szCur = szPath + lstrlenW(szPath);
169        szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
170     szCur--;
171
172   if (szCur == szPath)
173     return szCur;
174   else
175     return szCur + 1;
176
177 #undef SLASH
178 }
179
180 /***********************************************************************
181  *              DllGetClassObject (AVIFIL32.@)
182  */
183 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
184 {
185   TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
186
187   if (pclsid == NULL || piid == NULL || ppv == NULL)
188     return E_FAIL;
189
190   return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
191 }
192
193 /*****************************************************************************
194  *              DllCanUnloadNow         (AVIFIL32.@)
195  */
196 HRESULT WINAPI DllCanUnloadNow(void)
197 {
198   return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
199 }
200
201 /*****************************************************************************
202  *              DllMain         [AVIFIL32.init]
203  */
204 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
205 {
206   TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
207
208   switch (fdwReason) {
209   case DLL_PROCESS_ATTACH:
210     DisableThreadLibraryCalls(hInstDll);
211     AVIFILE_hModule = hInstDll;
212     break;
213   case DLL_PROCESS_DETACH:
214     break;
215   };
216
217   return TRUE;
218 }