ReactOS  0.4.13-dev-563-g0561610
factory.c
Go to the documentation of this file.
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 #include "rpcproxy.h"
30 
31 #include "initguid.h"
32 #include "vfw.h"
33 #include "avifile_private.h"
34 
35 #include "wine/debug.h"
36 
38 
40 
43 
44 typedef struct
45 {
46  IClassFactory IClassFactory_iface;
47  LONG ref;
50 
52 {
53  return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 }
55 
57  void **ppobj)
58 {
59  TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
60 
61  if ((IsEqualGUID(&IID_IUnknown, riid)) ||
63  *ppobj = iface;
64  IClassFactory_AddRef(iface);
65  return S_OK;
66  }
67 
68  return E_NOINTERFACE;
69 }
70 
72 {
75 
76  TRACE("(%p) ref = %u\n", This, ref);
77  return ref;
78 }
79 
81 {
84 
85  TRACE("(%p) ref = %u\n", This, ref);
86 
87  if(!ref)
89 
90  return ref;
91 }
92 
94  REFIID riid, void **ppobj)
95 {
97 
98  TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
99  ppobj);
100 
101  if (!ppobj)
102  return E_INVALIDARG;
103  *ppobj = NULL;
104 
105  if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
106  return E_INVALIDARG;
107 
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);
112 
113  if (pOuter)
114  return CLASS_E_NOAGGREGATION;
115 
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);
120 
121  return E_NOINTERFACE;
122 }
123 
125 {
126  TRACE("(%p,%d)\n",iface,dolock);
127 
128  AVIFILE_bLocked = dolock;
129 
130  return S_OK;
131 }
132 
133 static const IClassFactoryVtbl iclassfact = {
139 };
140 
141 static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
142 {
144  HRESULT hr;
145 
146  *ppv = NULL;
147 
148  cf = HeapAlloc(GetProcessHeap(), 0, sizeof(*cf));
149  if (!cf)
150  return E_OUTOFMEMORY;
151 
152  cf->IClassFactory_iface.lpVtbl = &iclassfact;
153  cf->ref = 1;
154  cf->clsid = *clsid;
155 
156  hr = IClassFactory_QueryInterface(&cf->IClassFactory_iface, riid, ppv);
157  IClassFactory_Release(&cf->IClassFactory_iface);
158 
159  return hr;
160 }
161 
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  */
184 {
185  HRESULT hr;
186 
187  TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
188 
189  if (pclsid == NULL || piid == NULL || ppv == NULL)
190  return E_FAIL;
191 
192  hr = AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193  if (SUCCEEDED(hr))
194  return hr;
195 
196  return avifil32_DllGetClassObject(pclsid,piid,ppv);
197 }
198 
199 /*****************************************************************************
200  * DllCanUnloadNow (AVIFIL32.@)
201  */
203 {
204  return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
205 }
206 
207 /*****************************************************************************
208  * DllMain [AVIFIL32.init]
209  */
211 {
212  TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
213 
214  switch (fdwReason) {
215  case DLL_PROCESS_ATTACH:
216  DisableThreadLibraryCalls(hInstDll);
217  AVIFILE_hModule = hInstDll;
218  break;
219  };
220 
221  return TRUE;
222 }
223 
224 /***********************************************************************
225  * DllRegisterServer (AVIFIL32.@)
226  */
228 {
230 }
231 
232 /***********************************************************************
233  * DllUnregisterServer (AVIFIL32.@)
234  */
236 {
238 }
static IClassFactory * cf
HRESULT WINAPI avifil32_DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv) DECLSPEC_HIDDEN
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
static HRESULT WINAPI IClassFactory_fnLockServer(IClassFactory *iface, BOOL dolock)
Definition: factory.c:124
#define E_NOINTERFACE
Definition: winerror.h:2364
LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
Definition: factory.c:162
IClassFactory IClassFactory_iface
Definition: inetcomm_main.c:74
HRESULT hr
Definition: shlfolder.c:183
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HMODULE AVIFILE_hModule
Definition: factory.c:39
WINE_DEFAULT_DEBUG_CHANNEL(devenum)
static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
Definition: factory.c:71
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:112
HRESULT AVIFILE_CreateACMStream(REFIID riid, LPVOID *ppv)
Definition: acmstream.c:704
static HRESULT WINAPI IClassFactory_fnQueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
Definition: factory.c:56
static const IClassFactoryVtbl iclassfact
Definition: factory.c:133
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT AVIFILE_CreateAVIFile(IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: avifile.c:646
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
HRESULT WINAPI DllRegisterServer(void)
Definition: factory.c:227
#define lstrlenW
Definition: compat.h:407
#define E_FAIL
Definition: ddrawi.h:102
static IClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: factory.c:51
HRESULT AVIFILE_CreateWAVFile(IUnknown *outer_unk, REFIID riid, void **ret_iface) DECLSPEC_HIDDEN
Definition: wavfile.c:979
Definition: send.c:47
static const WCHAR avifile[]
Definition: avisplitter.c:273
static IN DWORD IN LPVOID lpvReserved
struct tagIClassFactoryImpl IClassFactoryImpl
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
Definition: factory.c:183
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define SLASH(w)
static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
Definition: factory.c:141
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI DllUnregisterServer(void)
Definition: factory.c:235
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
Definition: factory.c:210
LONG HRESULT
Definition: typedefs.h:77
static UINT AVIFILE_uUseCount
Definition: factory.c:42
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT AVIFILE_CreateICMStream(REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN
Definition: icmstream.c:727
REFCLSID clsid
Definition: msctf.c:84
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
static BOOL AVIFILE_bLocked
Definition: factory.c:41
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
Definition: factory.c:80
LPCWSTR szPath
Definition: env.c:35
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
unsigned int ULONG
Definition: retypes.h:1
HRESULT WINAPI DllCanUnloadNow(void)
Definition: factory.c:202
const GUID IID_IClassFactory
static HRESULT WINAPI IClassFactory_fnCreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **ppobj)
Definition: factory.c:93
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57