Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/avifil32/factory.c
4389 views
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
37
WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38
39
HMODULE AVIFILE_hModule = NULL;
40
41
typedef struct
42
{
43
IClassFactory IClassFactory_iface;
44
LONG ref;
45
CLSID clsid;
46
} IClassFactoryImpl;
47
48
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
49
{
50
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51
}
52
53
static HRESULT WINAPI IClassFactory_fnQueryInterface(IClassFactory *iface, REFIID riid,
54
void **ppobj)
55
{
56
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
57
58
if ((IsEqualGUID(&IID_IUnknown, riid)) ||
59
(IsEqualGUID(&IID_IClassFactory, riid))) {
60
*ppobj = iface;
61
IClassFactory_AddRef(iface);
62
return S_OK;
63
}
64
65
return E_NOINTERFACE;
66
}
67
68
static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
69
{
70
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
71
ULONG ref = InterlockedIncrement(&This->ref);
72
73
TRACE("(%p) ref = %lu\n", This, ref);
74
return ref;
75
}
76
77
static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
78
{
79
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80
ULONG ref = InterlockedDecrement(&This->ref);
81
82
TRACE("(%p) ref = %lu\n", This, ref);
83
84
if(!ref)
85
free(This);
86
87
return ref;
88
}
89
90
static HRESULT WINAPI IClassFactory_fnCreateInstance(IClassFactory *iface, IUnknown *pOuter,
91
REFIID riid, void **ppobj)
92
{
93
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
94
95
TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
96
ppobj);
97
98
if (!ppobj)
99
return E_INVALIDARG;
100
*ppobj = NULL;
101
102
if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
103
return E_INVALIDARG;
104
105
if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
106
return AVIFILE_CreateAVIFile(pOuter, riid, ppobj);
107
if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
108
return AVIFILE_CreateWAVFile(pOuter, riid, ppobj);
109
110
if (pOuter)
111
return CLASS_E_NOAGGREGATION;
112
113
if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
114
return AVIFILE_CreateICMStream(riid,ppobj);
115
if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
116
return AVIFILE_CreateACMStream(riid,ppobj);
117
118
return E_NOINTERFACE;
119
}
120
121
static HRESULT WINAPI IClassFactory_fnLockServer(IClassFactory *iface, BOOL dolock)
122
{
123
TRACE("(%p,%d)\n",iface,dolock);
124
125
return S_OK;
126
}
127
128
static const IClassFactoryVtbl iclassfact = {
129
IClassFactory_fnQueryInterface,
130
IClassFactory_fnAddRef,
131
IClassFactory_fnRelease,
132
IClassFactory_fnCreateInstance,
133
IClassFactory_fnLockServer
134
};
135
136
static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
137
{
138
IClassFactoryImpl *cf;
139
HRESULT hr;
140
141
*ppv = NULL;
142
143
cf = malloc(sizeof(*cf));
144
if (!cf)
145
return E_OUTOFMEMORY;
146
147
cf->IClassFactory_iface.lpVtbl = &iclassfact;
148
cf->ref = 1;
149
cf->clsid = *clsid;
150
151
hr = IClassFactory_QueryInterface(&cf->IClassFactory_iface, riid, ppv);
152
IClassFactory_Release(&cf->IClassFactory_iface);
153
154
return hr;
155
}
156
157
LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
158
{
159
#define SLASH(w) ((w) == '/' || (w) == '\\')
160
161
LPCWSTR szCur;
162
163
for (szCur = szPath + lstrlenW(szPath);
164
szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
165
szCur--;
166
167
if (szCur == szPath)
168
return szCur;
169
else
170
return szCur + 1;
171
172
#undef SLASH
173
}
174
175
/***********************************************************************
176
* DllGetClassObject (AVIFIL32.@)
177
*/
178
HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
179
{
180
HRESULT hr;
181
182
TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
183
184
if (pclsid == NULL || piid == NULL || ppv == NULL)
185
return E_FAIL;
186
187
hr = AVIFILE_CreateClassFactory(pclsid,piid,ppv);
188
if (SUCCEEDED(hr))
189
return hr;
190
191
return avifil32_DllGetClassObject(pclsid,piid,ppv);
192
}
193
194
/*****************************************************************************
195
* DllMain [AVIFIL32.init]
196
*/
197
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
198
{
199
TRACE("(%p,%ld,%p)\n", hInstDll, fdwReason, lpvReserved);
200
201
switch (fdwReason) {
202
case DLL_PROCESS_ATTACH:
203
DisableThreadLibraryCalls(hInstDll);
204
AVIFILE_hModule = hInstDll;
205
break;
206
};
207
208
return TRUE;
209
}
210
211